填写后,所需输入仍然无效

时间:2016-01-02 16:05:45

标签: html twitter-bootstrap

我有以下简单的登录表单,其中包含' required'密码:

 <div id="navbar" class="navbar-collapse collapse">
   <ul class="nav navbar-nav navbar-right">
     <form action="/login" class="navbar-form navbar-right" method="post">
       <div class="form-group">
         <input type="text" class="form-control" name="username" placeholder="Login">
       </div>
       <div class="form-group">
         <input type="password" class="form-control" name="pwd" placeholder="Password" 
                required oninvalid="this.setCustomValidity('Please enter your password')">
       </div>
       <button type="submit" class="btn btn-primary">Log in</button>
     </form>
   </ul>
</div>

如果用户点击&#34;登录&#34;并且pwd输入为空,错误消息将按预期显示,但是如果用户在尝试失败后输入密码,则错误消息将再次出现,使得&#34;登录&#34;按钮不可伸缩(即使此时pwd中有输入),直到pwd输入失去焦点。 (我正在使用bootstrap 3.3.5和chrome浏览器。)
我该如何解决这个错误?

1 个答案:

答案 0 :(得分:0)

oninvalid =“!this.value || this.setCustomValidity('请输入您的密码')”

相关问题