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);
}
}

本文介绍如何使用JQuery实时监听文本框的变化和实现长按事件的处理。详细展示了通过'on'方法结合'inputpropertychange'事件来响应文本框内容的更新,并提供了一段用于监听长按事件的自定义JQuery插件代码。
473

被折叠的 条评论
为什么被折叠?



