JQuery 實時監聽文字框變化
阿新 • • 發佈:2018-11-07
文章目錄
JQuery 實時監聽文字框變化
使用 input propertychange
html 的文字框
<input thpe="text" id= "theId" name="theId" />
js 程式碼
$(function(){
$('#theId').on('input propertychange', function() {
//這裡加你需要的邏輯
});
});
JS 監聽長按事件
$(function(){
$(function(){ $("#被監聽的元素id").longPress(function(){ alert(1); }); });
方法
$.fn.longPress = function(fn) {
var timeout = undefined;
var $this = this;
for(var i = 0;i<$this.length;i++){
$this[i].addEventListener('touchstart', function(event) {
timeout = setTimeout(fn, 800);
}, false );
$this[i].addEventListener('touchend', function(event) {
clearTimeout(timeout);
}, false);
}
}