如何在按钮的Click事件中使用Javascript代码 [英] How to use Javascript Code in a button's Click event
本文介绍了如何在按钮的Click事件中使用Javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在asp页面的脚本标签中编写了javascript函数,并调用了按钮的函数OnClick事件。
但是当我单击按钮时它不起作用并显示一个错误消息,按钮确实不包含我在上面声明的函数。请帮帮我。
Mohi Uddin
解决方案
我给你举个例子来帮助你
< script type = text / javascript >
函数validate()
{
if(document.getElementById( <% = txtName.ClientID %> )。value == 0)
{
alert(请输入姓名);
document.getElementById(<% = txtName.ClientID %> )。焦点();
返回false;
}
< / script >
< asp:button id =btnAddtext =Addrunat =serveronclientclick =javascript:return validate( );/>
I have written javascript function in script tag in asp page and called the function OnClick event of a button.
But when I click the button it does not work and show an error message that button does not contain a function that I declared above. Please help me.
Mohi Uddin
解决方案
i''m giving you an example it will help you
<script type="text/javascript"> function validate() { if(document.getElementById("<%=txtName.ClientID %>").value == 0) { alert("Please Enter Name"); document.getElementById("<%=txtName.ClientID %>").focus(); return false; } </script>
<asp:button id="btnAdd" text="Add" runat="server" onclientclick="javascript:return validate();"/>
这篇关于如何在按钮的Click事件中使用Javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文