我想在每次特定输入框的值改变时执行一个函数。它几乎适用于$('input').keyup(function),但当将文本粘贴到框中时不会发生任何事情,例如。$input.change(函数)只在输入模糊时触发,所以我如何立即知道文本框改变了值?
当前回答
试试这个:
$("input").bind({
paste : function(){
$('#eventresult').text('paste behaviour detected!');
}
})
其他回答
试试这个. .致谢至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。
试试这个:
$("input").bind({
paste : function(){
$('#eventresult').text('paste behaviour detected!');
}
})
更新- 2021年
从2021年起,你可以使用输入事件来处理所有事件的输入值变化。
$("#myTextBox").on("input", function() {
alert($(this).val());
});
原来的答案
只需要记住,'on'建议使用'bind'函数,所以总是尝试使用这样的事件监听器:
$("#myTextBox").on("change paste keyup", function() {
alert($(this).val());
});
您还可以使用文本框事件-
<input id="txt1" type="text" onchange="SetDefault($(this).val());" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
function SetDefault(Text){
alert(Text);
}
试试这个
用这个: https://github.com/gilamran/JQuery-Plugin-AnyChange
它处理所有改变输入的方法,包括内容菜单(使用鼠标)
推荐文章
- 可以在setInterval()内部调用clearInterval()吗?
- 无法读取未定义的属性“msie”- jQuery工具
- jQuery:执行同步AJAX请求
- jQuery表格排序
- 如何禁用文本选择使用jQuery?
- 如何停止事件冒泡复选框点击
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何删除和清除所有的本地存储数据
- 如何修改标签文本?
- 如何获得十六进制颜色值而不是RGB值?
- 如何将一个标题转换为jQuery的URL段塞?
- $(window).width()与媒体查询不一样
- AJAX请求中的内容类型和数据类型是什么?
- 如何打破_。在underscore.js中的每个函数
- 如何在jQuery中获得当前日期?