加个提示
字数不够  ,  字数过多   分开提示少于3个字,提示字数不够
大于12个字,提示字数过多
现在的提示不明了,
  if($('#feiyong').val().length<3 || $('#feiyong').val().length>12){
            $("#jchfeiyong").remove();
            $('#feiyong').parent().append('<span id="jchfeiyong" style="color:red;">*字数不够或者过多</span>');
           // $("#jchfeiyong").fadeOut(50000);
            $('#feiyong').focus();
            $('#feiyong').blur(function(){
                 if($('#feiyong').val().length>3)$("#jchfeiyong").remove();
             });
            cha=cha && false;
        }

解决方案 »

  1.   


    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <div>
      <input type="text" name="" id="feiyong">
    </div>
    <script>
      $('#feiyong').on('blur', function () {
        var val = $(this).val()
        $('#jchfeiyong').remove()
        if (val) {
          if (val.length < 3) {
            $(this).parent().append('<span id="jchfeiyong" style="color:red;">*字数不够</span>')
          } else if (val.length > 13) {
            $(this).parent().append('<span id="jchfeiyong" style="color:red;">*字数过多</span>')
          }
        } else {
          $(this).parent().append('<span id="jchfeiyong" style="color:red;">*空值</span>')
        }
      })
    </script>