您现在的位置是:首页 > 电脑技术查询 > web开发

哪位大哥帮帮忙~该怎么解决

编辑:chaxungu时间:2022-10-02 23:18:48分类:web开发

哪位大哥帮帮忙~~
请问大家,我想实现在表单内计算的功能,代码如下,但就是实现不了,请帮帮忙,小弟下跪了。。
==================我是分隔线==============================

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<script type= "text/javascript " language= "javascript ">
<!--

function calc()
{
var x=document.form1.textfield.value;
var y=document.form1.textfield2.value;
var z=parseFloat(x)*parseFloat(y);
document.form1.textfield3.value=z;
}
//-->
</script>


</head>

<body>
<form id= "form1 " name= "form1 " method= "post " action= " ">
<label> 1
<input type= "text " name= "textfield " />
</label>
<p>
<label> 2
<input type= "text " name= "textfield2 " />
</label>
</p>
<p>
<label> 3
<input type= "text " name= "textfield3 " />
</label>
</p>
<p>
<label>
<input type= "submit " name= "Submit " value= "提交 " onclick= "calc() " />
</label>
</p>
</form>
<p> &nbsp; </p>
</body>
</html>


------解决方案--------------------
<input type= "submit " name= "Submit " value= "提交 " onclick= "calc() " />

改成
<input type= "button " name= "Submit " value= "提交 " onclick= "calc() " />

试试


------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<script type= "text/javascript " language= "javascript ">
<!--

function calc()
{
var x=document.form1.textfield.value;
var y=document.form1.textfield2.value;
var z=parseFloat(x)*parseFloat(y);
document.form1.textfield3.value=z;
}
//-->
</script>


</head>

<body>
<form id= "form1 "
<label> 1
<input type= "text " name= "textfield " />
</label>
<p>
<label> 2
<input type= "text " name= "textfield2 " />
</label>
</p>
<p>
<label> 3
<input type= "text " name= "textfield3 " />
</label>