How to track change in textbox using jQuery

淺唱寂寞╮ 提交于 2019-12-22 17:54:24

问题


I want to check if user changes the value of a textbox. If the user changes the value, then I want to display the changed value in a different textbox.


回答1:


jquery has an event for this, .change(), this event will detect content changes when the textbox looses focus.

If you are wanting to detect the change at every keypress, .keyup() and .keydown() might be better suited for your needs.

Examples for your intended use:

//just change '.change' to '.keyup' or '.keydown' the rest is the same.
$('input').change(function() {
    $('target').val(this.value);
});


来源:https://stackoverflow.com/questions/4911832/how-to-track-change-in-textbox-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!