本文介绍了将asp:TextBox传递给java脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 亲爱的, 我有这个功能: function myFunction(id) { var x; x = document.getElementById(id)。 value ; if (isNaN(x)|| x == ) { alert(' 问题输入'); return false ; } 其他 { 返回 真; } } 我想将文本框值传递给函数用于验证。我尝试了以下方法: < asp:ImageButton ID = imageButtonView runat = server 高度 = 60px 工具提示 = بحث 宽度 = 60px BorderStyle = Solid ImageUrl = 〜/ Images / searchButton .jpg OnClick = imageButtonView_Click OnClientClick = 返回myFunction('<% = textBoxCustomerCode.ClientID %> '); / > 但它不起作用。知道如何将值传递给函数。 提前致谢。解决方案 您好,尝试使用下面的javacript功能: function myFunction() { var x; x = document.getElementById(' <%= textBoxCustomerCode.ClientID%>') 。 value ; if (isNaN(x)|| x == ) { alert(' 问题输入'); return false ; } 其他 { 返回 真; } } 通过以下代码调用该函数: < asp:ImageButton ID = imageButtonView runat = server 高度 = 60px 工具提示 = بحث 宽度 = 60px BorderStyle = 实体 ImageUrl = 〜/ Images / searchButton.jpg OnClick = imageButtonView_Click OnClientClick = return myFunction(); / > 如果你想使用Jquery获取文本框值,请执行以下操作 var val = ( #txt1)。val(); 如果你想使用Javascript获取文本框值,请按照下面的说法 var val = document .getElementById(' <%= txt1.ClientID%GT;')值; Dear all, I have this function: function myFunction(id){ var x; x = document.getElementById(id).value; if(isNaN(x) || x == "") { alert('Problem input'); return false; } else { return true; } }I want to pass textbox value to the function for the verification. I tried the following: <asp:ImageButton ID="imageButtonView" runat="server" Height="60px" ToolTip="بحث" Width="60px" BorderStyle="Solid" ImageUrl="~/Images/searchButton.jpg" OnClick="imageButtonView_Click" OnClientClick="return myFunction('<%=textBoxCustomerCode.ClientID%>');"/>but it does not work. Any idea how to pass the value to the function. Thanks in advance. 解决方案 Hi, try to use javacript funcion below:function myFunction(){ var x; x = document.getElementById('<%= textBoxCustomerCode.ClientID %>').value; if(isNaN(x) || x == "") { alert('Problem input'); return false; } else { return true; } }call the function by code below: <asp:ImageButton ID="imageButtonView" runat="server" Height="60px" ToolTip="بحث" Width="60px" BorderStyle="Solid" ImageUrl="~/Images/searchButton.jpg" OnClick="imageButtonView_Click" OnClientClick="return myFunction();"/>If you want to get textbox value using Jquery do like belowvar val =("#txt1").val();If you want to get textbox value using Javascript do like belowvar val = document.getElementById('<%=txt1.ClientID%>').value; 这篇关于将asp:TextBox传递给java脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 13:53