简体   繁体   English

功能上的jQuery无法在引导模式下工作

[英]Jquery on function not working in a bootstrap modal

im having trouble triggering an event in jquery. 即时通讯在触发jquery中的事件时遇到问题。 Thing is i have set an on change event on a bootstrap modal input field. 我在引导模式输入字段上设置了一个on change事件。 The event triggers when i close my modal, i want it to trigger even when modal is open. 当我关闭模态时,事件触发,即使模态打开,我也希望它触发。 Please help. 请帮忙。 Thanks 谢谢

<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 main.js

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

使用onBlur或KeyUp事件,而不要使用“更改”。

Try with blur() event 尝试使用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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM