1.首先我們會想到change事件
此方法有缺陷,需要失去焦點才會觸發,有輸入即觸發的需求時,不適用
$("#id").on('change',function(e) { console.log(e.delegateTarget.value); //其他執行代碼 });
2.其次,keyup,也可以觸發
此方法有兼容性問題,Chrome和IE,遇到中文輸入時,打入拼音后,必須空格選擇中文,如果使用數字選擇鍵,事件將不會觸發.
但360極速模式,可以正常使用,費解!
$("#id").on('keyup',function(e) { console.log(e.delegateTarget.value); //其他執行代碼 });
3.推薦使用,input
目前所有瀏覽器都適用
$("#id").on('input',function(e) { console.log(e.delegateTarget.value); //其他執行代碼 });