赞
踩
dom.on("input",function(){
searchTrigger($(this));
});
function searchTrigger(self){
//此处处理搜索事件
}
let flag=true; dom.on({ compositionstart: function () { flag = true; }, compositionend: function () { flag = false; }, input: function (e) { let self = $(this); setTimeout(function () { if (!flag) { searchTrigger(self); } },0); }); function searchTrigger(self){ //此处处理搜索事件 }
let flag = false; dom.on({ compositionstart: function () { flag = true; }, compositionend: function () { flag = false; searchTrigger($(this)); }, input: function (e) { searchTrigger($(this)); }, keypress: function (e) { let self = $(this); if (e.keyCode == 13) { flag=false; searchTrigger(self); } } }); function searchTrigger(self){ if(!flag){ //此处处理搜索事件 } }
(function ($) { $.fn.SearcherTrigger = function (opts) { searchFun($(this), opts); } function searchFun(searchDOM, opts) { var defalutOpts = { emptySpace: true,//清空空格 delay: true, //是否延时触发搜索 delayTime: 500 //延时触发时间 } opts = opts || {}; opts = $.extend(defalutOpts, opts); opts.searchLock = true; //搜索锁 opts.temporaryStorage = ""; //临时存储空间 (function searchBindEvent() { searchDOM.on('compositionstart', function () { opts.searchLock = false; }); searchDOM.on('compositionend', function () { opts.searchLock = true; searchTrigger(); }); searchDOM.on("input", function (e) { e.preventDefault(); searchTrigger(); }); })(); function searchTrigger() { if (!opts.searchLock) return; emptySpaceFun(); let searchStoragel = searchDOM.val(); if (!(searchStoragel.length > 1 && opts.temporaryStorage !== searchStoragel)) { opts.error && opts.error(); return; } opts.temporaryStorage = searchStoragel; delayTrigger(); } function emptySpaceFun() { if (!opts.emptySpace) return; searchDOM.val(searchDOM.val().replace(/[ ]/g, "")); } function delayTrigger() { opts.delay ? setTimeout(function () { resultTrigger(); }, opts.delayTime) : resultTrigger(); function resultTrigger() { opts.sucess && opts.sucess(opts.temporaryStorage); } } } })(jQuery);
$("#input").SearcherTrigger({
sucess:function(value){
},
error:function(){
}
})
关于插件,要是有的好的想法,可以留言给我.谢谢.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。