首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

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

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

<!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>


</p>
<p>
<label>
<input type= "button " value= "提交 " onclick= "calc() " />
</label>
</p>
</form>
<p> &nbsp; </p>
</body>
</html>

这样就可以拉

[解决办法]
submit类型按钮click之后会提交form,调用action
submit类型的按钮一般对应的方法是 onsubmit
<input type= "submit " name= "Submit " value= "提交 " onsubmit= "return calc() " />
执行提交前的数据校验

button的话click后执行onclick里的方法.

热点排行