Yos*_*ati 2 html javascript jquery
如何在动态更改时检测输入值的更改.因为txt2上的更改清除了txt1中的值.我需要检测它已清除或更改.
Onchange不会这样做.
<input id="txt1" type="text" onchange="SetDefault();" onpaste="this.onchange();" oninput="this.onchange();">
<br>
<input id="txt2" type="text" onchange="SetDefaultSecond();" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
<script>
function SetDefault(){
alert("Change1");
}
function SetDefaultSecond(){
$("#txt1").val('');
alert("Change2");
}
</script>
Run Code Online (Sandbox Code Playgroud)
清除第一个输入时,您可以手动触发输入事件,如下所示:
<input id="txt1" type="text">
<br>
<input id="txt2" type="text">
<script>
$("#txt1").on("input", function() {
alert("Change1");
});
$("#txt2").on("input", function() {
$("#txt1").val('').trigger('input');
alert("Change2");
});
</script>
Run Code Online (Sandbox Code Playgroud)
jsFiddle这里:https://jsfiddle.net/dr0oabj1/
| 归档时间: |
|
| 查看次数: |
5133 次 |
| 最近记录: |