码迷,mamicode.com
首页 > 其他好文 > 详细

OnClientClick是button的客户端事件

时间:2015-03-28 23:08:51      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

OnClick是button的服务器端事件

OnClientClick是button的客户端事件

一般我们用 OnClientClick验证我们的提交数据,但是这个一定要返回ture或者false,即一定要加上return,否则OnClick失效。当返回 false时OnClick服务器端事件才被中止,当你的js验证有错误,也会跳过验证,直接执行服务器端事件OnClientClick。

例:单击按钮判文本框是否为空

在.aspx文件中可以如下编写:  

<asp:TextBox   ID= "PwdText "   runat= "server "   TextMode= "Password "> </asp:TextBox> 

<asp:ImageButton   ID= "okButton "   runat= "server "   OnClientClick= "return   checkInput(); "   Text= "确定 "   />        

<script   type= "text/javascript "   language= "javascript ">                 

function   checkInput()                 

{                         

if(document.getElementById( " <%=PwdText.ClientID   %> ").value   ==   " ")     //带母版的取值方法                    

{                                 

alert( "请填写密码! ");                                 

return   false;                         

}                         

return   true;                 

}

</script>

若不带母版或用 if(document.getElementById( "PwdText ").value.length==0)判是否为空,

OnClientClick是button的客户端事件

标签:

原文地址:http://www.cnblogs.com/ios8859-1/p/4374961.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!