猿问

jquery validate.js 怎么判断动态提示信息是否显示

jquery validate.js可以在输入框输入内容后自动判别输入内容是否符合规则,如果不符合,会自动给出一个用`<label>`标签包裹的提示信息,怎么判断这个`<label>`是否显示?


我现在想要通过这个提示信息控制一个发送按钮是否禁用,如下代码所示:


$("#mobile").change(function(event){


   if( ($("label#mobile-error").show()) ){

   var info = $("label#mobile-error").text();

       if( info !== "" ){

          $button.prop("disabled",true);

          console.log("false");

          console.log(info);

       }else if( info == "" ){

           $button.prop("disabled",false);

           console.log("true");

           console.log(info);

       }

   }else{

       $button.prop("disabled",false);

       console.log("ok");

   }

});


但是第一次输入正确时,通过控制台,可以看到程序并不会执行else(console.log("ok");)。怎么判断这个label标签是否显示?


PIPIONE
浏览 506回答 1
1回答

烙印99

var validator = $("#form").validate({&nbsp; &nbsp; &nbsp; &nbsp; ....})$("#mobile").change(function(event){&nbsp; &nbsp;if( validator.element("#mobile") ){&nbsp; &nbsp; &nbsp; &nbsp; var info = $("label#mobile-error").text();&nbsp; &nbsp; &nbsp; &nbsp;if( info !== "" ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $button.prop("disabled",true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("false");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(info);&nbsp; &nbsp; &nbsp; &nbsp;}else if( info == "" ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$button.prop("disabled",false);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;console.log("true");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;console.log(info);&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp;}else{&nbsp; &nbsp; &nbsp; &nbsp;$button.prop("disabled",false);&nbsp; &nbsp; &nbsp; &nbsp;console.log("ok");&nbsp; &nbsp;}});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答