Jquery函数无法在bootstrap模式中工作

时间:2017-07-15 06:29:49

标签: javascript jquery

我无法在jquery中触发事件。事情是我在bootstrap模态输入字段上设置了一个on change事件。当我关闭我的模态时,事件会触发,即使模态打开,我也希望它触发。请帮忙。感谢

<div class="modal-body">
    <div class="col-md-6">
        <p>
        <span><strong> Current Password:</strong></span>                                                    
        <input type="password" class="form-control" id="curr-pass" placeholder="Enter Current Password" name="pass" required />
        </p>
    </div>
</div>

main.js

$(document).ready(function(){
    $(document).on("change","#curr-pass",function(){
        var password = $(this).val();
        console.log(password);
    });
});

2 个答案:

答案 0 :(得分:1)

使用onBlur或KeyUp事件而不是“更改”..

答案 1 :(得分:0)

尝试blur()事件

$(document).ready(function(){
    $(document).on("blur","#curr-pass",function(){
        var password = $(this).val();
        console.log(password);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal-body">
    <div class="col-md-6">
        <p>
        <span><strong> Current Password:</strong></span>                                                    
        <input type="password" class="form-control" id="curr-pass" placeholder="Enter Current Password" name="pass" required />
        </p>
    </div>
</div>