關于$("input").select();的問題
$("input").select(function(e){ ????alert(e.target.value) ????e.preventDefault(); }) $("#bt1").click(function(){ ????$("input").select(); })
來看上面代碼,這句
$("input").select();
為什么可以執行?按照道理,$("input").select綁定了一個匿名函數,這個函數需要接受一個參數e,就是鼠標選中某段文字的事件,可是當我點擊按鈕,并沒有哪段文字被選中,為何就可以觸發select事件?即使調用了這個函數select(),但是function中的e事件并沒有實際的點擊事件對應呀?
2018-10-10
按我的理解就是這一段代碼就是選中了input,$("input").select(function(e){
????
alert(e.target.value)
????
e.preventDefault();
})
后面那段代碼就是點擊后執行
2019-01-23
你應該理解
$("input").select(function(e){
????
alert(e.target.value)????
e.preventDefault();
})這個是對input的select事件定義的一個函數,而$("input").select()是對上面函數的調用,返回的內容就是input輸入框里面的內容,為什么能用就是jquery里面定義select事件的方法一的使用