我如何将这段代码放在按钮单击事件上 [英] how can i put this code on button click event

查看:89
本文介绍了我如何将这段代码放在按钮单击事件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将这段代码放在按钮单击事件中



how can i put this code on button click event



 <script type="text/javascript" language ="javascript" >
    Check()
    {
        var fours = document.getElementById("txt4s").value * 4
        var sixs = document.getElementById("txt6s").value * 6
        var totalrun = document.getElementById("txtRuns").value
        var totalruns = fours + sixs
        if (totalrun>totalruns)
         {
         return true;
         }
         else
         {
        
         alert("Total runs should be more then " + totalruns);
       
         return false;
         }
    }
</script>

推荐答案

尝试以下代码

try below code

<input TYPE="submit" value="Save" name="btnSubmit" onClick="Check()">


在cs文件中写此行
write this line in cs file
Btn.Attributes.Add("onclick", "return check();");


嘿,我的上面的答案是asp.

尝试在asp.net中的以下代码

在页面加载事件中添加此代码..

hey my above answer was for asp.

try below code in asp.net

add this code in page load event..

Button1.Attributes.Add("onclick", "return check();")



最主要的是...你错过了javascript ...
请参阅下面的正确脚本



and the main thing is that... u missed javascript...
see the correct script below

 <script type="text/javascript" language ="javascript" >
    function Check()
    {
        var fours = document.getElementById("txt4s").value * 4
        var sixs = document.getElementById("txt6s").value * 6
        var totalrun = document.getElementById("txtRuns").value
        var totalruns = fours + sixs
        if (totalrun>totalruns)
         {
         return true;
         }
         else
         {
        
         alert("Total runs should be more then " + totalruns);
       
         return false;
         }
    }
</script>


这篇关于我如何将这段代码放在按钮单击事件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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