提交按钮需要两次点击才能提交

时间:2015-07-30 15:40:36

标签: jquery twitter-bootstrap button submit

我制作了一个简短的jquery脚本来确认用户输入两次相同的密码。默认情况下,提交按钮处于非活动状态。如果用户输入匹配的密码,jquery()。html()要求按钮ro为活动按钮。

这一切都很好但用户需要按两次按钮才能处理表单。我该如何解决这个问题,以便浏览器(在chrome中测试)可以注册第一次点击:

元素

<div id="notif"> <button type="submit" class="btn btn-info    disabled">Submit</button></div>

JS

<script>
function checkPasswordMatch() {
    var password = $("#txtNewPassword").val();
    var confirmPassword = $("#txtConfirmPassword").val();
if (password != confirmPassword)
    $("#notif").html("<button type='submit' class='btn btn-danger disabled'><i class='fa fa-exclamation-triangle'></i> Submit</button><p style='margin-left: 10px; color:#FF0000; font-weight: bold; display: inline;'>Passwords Do Not Match</p>");
else
    $("#notif").html("<button type='submit' class='btn btn-success active'><i class='fa fa-check'></li> Submit</button>");
                                }
$(document).ready(function () {
    $("#txtConfirmPassword").keyup(checkPasswordMatch);
                                });
</script>

1 个答案:

答案 0 :(得分:0)

我想您需要启用button而不是.html()。也许是这样的。还要在按钮html中添加disabled属性

var password = $("#txtNewPassword").val();
    var confirmPassword = $("#txtConfirmPassword").val();
if (password != confirmPassword)
    $("#notif").html("<button type='submit' class='btn btn-danger disabled'><i class='fa fa-exclamation-triangle'></i> Submit</button><p style='margin-left: 10px; color:#FF0000; font-weight: bold; display: inline;'>Passwords Do Not Match</p>");
else
    $("#notif").find("button").attr("disabled",false);
                                }

如果可能的话,请提供一个小提琴。

相关问题