简体   繁体   中英

Jquery on function not working in a bootstrap modal

im having trouble triggering an event in jquery. Thing is i have set an on change event on a bootstrap modal input field. 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

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

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

Try with blur() event

 $(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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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