function fieldValidation()
{
//alert("Email: "+document.getElementById("txbemail1").value);
var emailExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([com\co\.\in])+$/;
var str = document.getElementById("txbemail1").value;
var result = "Hello...!";
if (str != '')
{
if (!(emailExp.test(str)))
{
result += "\n Invalid Email";
}
}
else
{
result += "\n Email1";
}
alert("Error Detail: " + result);
}
HTML:
<asp:TextBox ClientIDMode="Static" id="txbemail1" runat="server" Width="150px" OnTextChanged="txbemail1_TextChanged"></asp:TextBox>
<asp:Button ID="btnnext" runat="server" OnClientClick="return fieldValidation();" OnClick="btnnext_Click" Text="Next" />
当调用javascript函数时只执行第一个语句而不是后续语句,为什么会这样......?
答案 0 :(得分:0)
How to change the value of an asp:textbox from javascript
根据这个你可以将ClientIDMode属性设置为Static,因此aso将在客户端生成相同的id。
<asp:TextBox ClientIDMode="Static" ID="txbemail1"
runat="server" Width="150px" OnTextChanged="txbemail1_TextChanged"></asp:TextBox>