问答详情
源自:3-14 表单提示信息

怎么结合jquery实现验证

<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>测试验证</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">

    </head>

  <body>

  <form id="form">

    <div class="form-group has-feedback id=""form1">

      姓名:<input type="text" id="input1" placeholder="请输入姓名" >

      <span id="s1" style="display:none">你输入的信息是正确的</span>

    <span id="ss1" class="glyphicon glyphicon-ok form-control-feedback" style="display:none"></span>

    <span id="w1" style="display:none">请输入正确信息</span>

    <span id="ww1" class="glyphicon glyphicon-warning-sign form-control-feedback" style="display:none"></span>

    <span id="e1" style="display:none">验证不通过</span>

    <span id="ee1" class="glyphicon glyphicon-remove form-control-feedback" style="display:none"></span>

    </div>

        <div class="form-group has-feedback"

        id="form2">

      学号:<input type="text" id="input2" placeholder="请输入学号" >

      <span style="display:none">你输入的信息是正确的</span>

    <span class="glyphicon glyphicon-ok form-control-feedback" style="display:none"></span>

    <span style="display:none">请输入正确信息</span>

    <span class="glyphicon glyphicon-warning-sign form-control-feedback" style="display:none"></span>

    <span style="display:none">验证不通过</span>

    <span class="glyphicon glyphicon-remove form-control-feedback" style="display:none"></span>

    </div>

    <button type="submit" class="btn btn-primary" id="submit">提交</button>

  </form>

   <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>

    <script src="js/bootstrap.min.js"></script>

    <script>

$("#submit").click(function(){

if($("#input1").val()==null)

{

$("#form1").addClase("has-warning");

$("#w1").show();

$("#ww1").show();

}

});

</script>

  </body>

  </html>

这样子写实现不了,<script></script>里是不是有问题

提问者:hello_world_ 2015-02-04 22:02

个回答

  • cooper_hou
    2015-02-05 11:37:09
    已采纳

    你把null改成0试试

  • lpandxhj
    2015-05-28 11:57:38

    你的addClass 也是拼错了。。。

  • 品茗见南山
    2015-05-22 14:26:50

    你把null和“”都去掉。换成if(!$("#input1").val()){          ...            

    }

    他会把你判断的无值,未定义等判为false