JScript codevar v=document.getElementById("txtName").value;
if(v=="")
{
alert('不能为空!');
retrun false;}
else
{
return true;
}
姓名:<asp:TextBox ID="txtName" runat="server" ><asp:TextBox>怎么调用验证函数

解决方案 »

  1.   

    button按钮
    onclientClick="return check();
    function check()
    {
    return true;
    }
      

  2.   

     function check()
    {
     var v=document.getElementById("txtName").value;
    if(v=="")
    {
    alert('不能为空!');
    retrun false;}
    else
    {
    return true;
    }
    }
     <asp:TextBox ID="txtName" runat="server" onblur=" check();" ><asp:TextBox>
      

  3.   

    在 提交按钮上写 OnClientClick 属性,在用户提交数据前对其进行验证,如下所示:
    <script type="text/javascript">
    function chkSubmit()
    {
    if( 检查通过 ) return true;
    else return false
    }
    </script><asp:Button ID="BtnSubmit" runat="server" OnClientClick="return chkSubmit();" Text="提交数据"></asp:Button>
      

  4.   

    function checkName()
    {
    var v=document.getElementById("txtName").value;
    if(v=="")
    {
    alert('不能为空!');
    retrun false;}
    else
    {
    return true;
    }
    }<asp:Button ID="btNameCheck" runat="server" onclick="checkName"><asp:Button>
      

  5.   

    JScript code
    function a()
    {
    var v=document.getElementById("txtName").value;
    if(v=="")
    {
    alert('不能为空!');
    retrun false;}
    else
    {
    return true;
    }
    }姓名:<asp:TextBox ID="txtName" runat="server" ><asp:TextBox>这样写:<asp:TextBox ID="txtName" runat="server" onkeyup="a()" ><asp:TextBox>
    或者在提交按钮上写<asp:button id="btn" runat="server" onClientClick="a()">
      

  6.   

    什么意思???
    小样  var v=document.getElementById("txtName").value; 它不报错!!!
    找到找getElementById("txtName")这东西吗??
    用这个事件onClientClick吧,是这个意思吗??
      

  7.   

    onclientClick="return check();
      

  8.   

    onclientclick中调用你的验证方法也可以写在onblur中
      

  9.   


    function check()
    {
    var v=document.getElementById("txtName").value;
    if(v=="")
    {
    alert('不能为空!');
    retrun false;}
    return true;
    }