Pre*_*ets 28 javascript asp.net
我有一个带有onchange事件的文本框.当用户使用自动填充功能填充文本框时,为什么此事件不会触发?
我正在使用Internet Explorer.有没有一个标准的,相对简单的解决方案来解决这个问题,而我不必禁用自动完成功能?
Tim*_*m C 12
之前我遇到过这个恼人的功能,当时我的解决方案是使用onfocus事件来记录文本框的当前值,然后使用onblur事件来检查当前值是否与onfocus期间保存的值相匹配.例如
<input type="text" name="txtTest" value="" onfocus="this.originalvalue=this.value" onblur="if (this.value != this.originalvalue) alert('Test has changed')"/>
Run Code Online (Sandbox Code Playgroud)
在Tim C的答案的基础上,这是我想出的一个简单的jquery来处理页面上所有文本框:
$("input[type=text]").bind("focus change",function(){
this.previousvalue = this.value;
}).blur(function(){
if (this.previousvalue != this.value){
$(this).change();
}
})
Run Code Online (Sandbox Code Playgroud)
如果您不关心onchange多次触发,可以使其更简单:
$("input[type=text]").blur(function(){
$(this).change();
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33285 次 |
| 最近记录: |