计算器在JavaScript中。提交值闪烁并消失。 :( [英] Calculator in javascript. on submit value flashes and disappears. :(

查看:52
本文介绍了计算器在JavaScript中。提交值闪烁并消失。 :(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
<head>
<title>Form Validation</title>
<script type="text/javascript">
function calculate()
{
var x=eval(document.getElementById("txt_area").value);
document.getElementById("txt_area").value = x;
}
function display(clicked_id)
{
    var pre = document.getElementById("txt_area").value;

    pre= pre + document.getElementById(clicked_id).value;

    document.getElementById("txt_area").value=pre;

}
</script>
</head>
<body>
         <form action="" name="myForm">
                 <table border="1">
                     <tr>
                       <td align="right"><input type="text name="text" id="txt_area"/></td>
                     </tr>
                     <tr>
                       <td align="right"> <input type="button" onclick="display(this.id)" id="1" value="1"/><input name="2" onclick="display(this.id)" id="2" type="button" value="2"/><input name="3" onclick="display(this.id)" id="3" type="button" value="3"/><input onclick="display(this.id)" id="+" type="button" value="+"/></td>
                     </tr>
                     <tr>
                       <td align="right"><input type="button" id="4" onclick="display(this.id)" value="4"/><input type="button" onclick="display(this.id)" id="5" name="5" value="5"/><input name="6" onclick="display(this.id)" id="6" type="button" value="6"/><input onclick="display(this.id)" id="-" type="button" value="-"/></td>
                     </tr>
                     <tr>
                        <td align="right"><input type="button" onclick="display(this.id)" id="7" value="7"/><input type="button" onclick="display(this.id)" id="8" value="8"/><input onclick="display(this.id)" id="9" type="button" value="9"/><input onclick="display(this.id)" id="*" type="button" value="*"/></td>
                     </tr>
                     <tr>
                         <td align="right"><input type="submit" value="Submit" onClick="calculate()"/></td>
                     </tr>
                </table>

         </form>

 </body>
 </html>

推荐答案

嘿那里,



你需要在计算并设置答案后阻止Button的PostBack,执行以下操作:



用以下内容替换您的提交按钮:
Hey there,

You need to prevent the Button's PostBack after it has calculated and set the answer, do this:

Replace your Submit button with this:
<input type="submit" value="Submit"  önclick="return calculate();" />



并在结束时添加一个false false()函数:


and add a return false at the end of calculate() function:

function calculate() {
            var x = eval(document.getElementById("txt_area").value);
            document.getElementById("txt_area").value = x;
            return false;
        }





如果有帮助请告诉我。



Azee ...



Let me know if it helps.

Azee...


只需按下从SUBMIT到BUTTON的按钮类型。这也有帮助。



谢谢Azee。
just chnaged the buttons type from SUBMIT to BUTTON. that helped too.

Thanks "Azee".


这篇关于计算器在JavaScript中。提交值闪烁并消失。 :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆