我想在每次特定输入框的值改变时执行一个函数。它几乎适用于$('input').keyup(function),但当将文本粘贴到框中时不会发生任何事情,例如。$input.change(函数)只在输入模糊时触发,所以我如何立即知道文本框改变了值?
当前回答
试试这个. .致谢至https://stackoverflow.com/users/1169519/teemu
在这里回答我的问题:https://stackoverflow.com/questions/24651811/jquery-keyup-doesnt-work-with-keycode-filtering?noredirect=1#comment38213480_24651811
这个解决方案帮助我在项目上取得进展。
$("#your_textbox").on("input propertychange",function(){
// Do your thing here.
});
注意:属性更改为低版本的IE。
其他回答
试试这个. .致谢至https://stackoverflow.com/users/1169519/teemu
在这里回答我的问题:https://stackoverflow.com/questions/24651811/jquery-keyup-doesnt-work-with-keycode-filtering?noredirect=1#comment38213480_24651811
这个解决方案帮助我在项目上取得进展。
$("#your_textbox").on("input propertychange",function(){
// Do your thing here.
});
注意:属性更改为低版本的IE。
用这个: https://github.com/gilamran/JQuery-Plugin-AnyChange
它处理所有改变输入的方法,包括内容菜单(使用鼠标)
试试这个:
$("input").bind({
paste : function(){
$('#eventresult').text('paste behaviour detected!');
}
})
您还可以使用文本框事件-
<input id="txt1" type="text" onchange="SetDefault($(this).val());" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
function SetDefault(Text){
alert(Text);
}
试试这个
试试这个:
基本上,只考虑每个事件:
Html:
<input id = "textbox" type = "text">
Jquery:
$("#textbox").keyup(function() {
alert($(this).val());
});
$("#textbox").change(function() {
alert($(this).val());
});