How to detect a textbox's content has changed

后端 未结 15 2027
猫巷女王i
猫巷女王i 2020-11-22 16:10

I want to detect whenever a textbox\'s content has changed. I can use the keyup method, but that will also detect keystrokes which do not generate letters, like the arrow ke

15条回答
  •  时光取名叫无心
    2020-11-22 16:14

    There's a complete working example here.

    
    jQuery Summing
    
    
    $(document).ready(function() {
    $('.calc').on('input', function() {
    var t1 = document.getElementById('txt1');
    var t2 = document.getElementById('txt2');
    var tot=0;
    if (parseInt(t1.value))
    tot += parseInt(t1.value);
    if (parseInt(t2.value))
    tot += parseInt(t2.value);
    document.getElementById('txt3').value = tot;
    });
    });
    
    
    
    
    
    
    
    
    

提交回复
热议问题