我想在每次特定输入框的值更改时执行函数.它几乎可以使用$('input').keyup(function),但是在将文本粘贴到框中时没有任何反应.$input.change(function)只有当输入模糊时触发,那么只要文本框的值发生变化,我怎么能立即知道?
Ale*_*lva 307
只是通过'bind'函数推荐'on',所以总是尝试使用这样的事件监听器:
$("#myTextBox").on("change paste keyup", function() {
alert($(this).val());
});
Run Code Online (Sandbox Code Playgroud)
dkn*_*ack 103
你可以使用jQuery的.bind()方法来做到这一点.看看jsFiddle.
HTML
<input id="myTextBox" type="text"/>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$("#myTextBox").bind("change paste keyup", function() {
alert($(this).val());
});
Run Code Online (Sandbox Code Playgroud)
小智 14
试试吧..来自/sf/users/81866361/
在这里回答我的问题: /sf/ask/1725626801/?noredirect=1#comment38213480_24651811
这个解决方案帮助我推进了我的项目.
$("#your_textbox").on("input propertychange",function(){
// Do your thing here.
});
Run Code Online (Sandbox Code Playgroud)
注意:IE的较低版本的propertychange.
你也可以使用文本框事件 -
<input id="txt1" type="text" onchange="SetDefault($(this).val());" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
function SetDefault(Text){
alert(Text);
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
基本上,只考虑每个事件:
网址:
<input id = "textbox" type = "text">
Run Code Online (Sandbox Code Playgroud)
查询:
$("#textbox").keyup(function() {
alert($(this).val());
});
$("#textbox").change(function() {
alert($(this).val());
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
343056 次 |
| 最近记录: |