2014-06-19 6 views
0

저는 양식이 있고 jquery 유효성 검사 jquery를 사용하고 있습니다. 테스트 데모입니다.버튼을 사용하여 jquery 유효성 검사를 트리거하는 방법

<script src="../JS/jquery.js" type="text/javascript"></script> 
    <script src="../JS/jquery.validate.js" type="text/javascript"></script> 
    <script language="javascript" type="text/javascript"> 
     $(function() { 
      $("#btns").click(function() { 
       if ($("<%=form1.ClientID %>").valid()) { 
        ajaxFunc();//ajax funcion to add email to db 
       } 

      }); 
     }); 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 

      <input id="cemail" type="email" name="email" required /> 
      <input class="submit" type="submit" value="Submit"/> 
      <input type="button" id="btns" value="btn"/> 
    </div> 
    </form> 
</body> 
</html> 

서브 미트를 사용할 때, Cemail 입력이 유효성을 검사하고 유효성 검사 메시지를 표시하고 입력 순서를 높게 줄을 지정하십시오.

하지만 버튼 클릭을 사용할 때 아무 것도 없었습니다. 버튼 onclick 기능을 사용할 때 어떻게 동일한 효과를 얻을 수 있습니까? 모두들.

+2

그것을 작동합니다 - http://jsfiddle.net/arunpjohny/AJ7jp/1/을 당신은 .valid'호출하기 전에 플러그인을 초기화하는'.validate을()'호출 할 필요가 –

+2

() '그것을 시험해보십시오. – Barmar

답변

1

선택자에 #가 없습니다. 즉 $("#<%=form1.ClientID %>")

$(function() { 
     $("#btns").click(function() { 
      if ($("#<%=form1.ClientID %>").valid()) { 
       ajaxFunc();//ajax funcion to add email to db 
      } 

     }); 
    }); 
관련 문제