How to call a function after textbox lose focus

前端 未结 3 1745
执念已碎
执念已碎 2021-02-19 20:03

I have no experience with Javascript/JQuery/AJAX so I\'m trying to understand if it\'s possible to call a function that execute a query on my DB after a textbox lose focus.

相关标签:
3条回答
  • 2021-02-19 20:08
    <input type="text" id="check">​
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    
    <script type="text/javascript">
    $("#check").blur(function() {
     alert('working');
    });​
    </script>
    
    0 讨论(0)
  • 2021-02-19 20:14

    Bind a handler to the change event:

    <textarea onchange='ajax_call()'></textarea>
    

    where ajax_call is a function for updating the DB.

    0 讨论(0)
  • 2021-02-19 20:26

    Yes, you can. First you need to wait for JavaScript event like onchange/onblur or other. Than you need to make an Ajax call to the server. It will change the data in db and can result some data, that you can put on the page. You can use jQuery to manipulate your page.

    Another way is to wait until a person presses submit button and than update data in the db.

    0 讨论(0)
提交回复
热议问题