JS判断用户连续输入
2016-12-15 09:43
246 查看
方案1
方案2.
[b]https://github.com/kenshin54/jquery-koala[/b][/code]
Load jQuery and koala:
Bind keyboard events to the dom with Koala.
Koala support descendant elements that are added to the document at a later time.
// // $('#element').donetyping(callback[, timeout=1000]) // Fires callback when a user has finished typing. This is determined by the time elapsed // since the last keystroke and timeout parameter or the blur event--whichever comes first. // @callback: function to be called when even triggers // @timeout: (default=1000) timeout, in ms, to to wait before triggering event if not // caused by blur. // Requires jQuery 1.7+ // ;(function($){ $.fn.extend({ donetyping: function(callback,timeout){ timeout = timeout || 1e3; // 1 second default timeout var timeoutReference, doneTyping = function(el){ if (!timeoutReference) return; timeoutReference = null; callback.call(el); }; return this.each(function(i,el){ var $el = $(el); // Chrome Fix (Use keyup over keypress to detect backspace) // thank you @palerdot $el.is(':input') && $el.on('keyup keypress',function(e){ // This catches the backspace button in chrome, but also prevents // the event from triggering too premptively. Without this line, // using tab/shift+tab will make the focused element fire the callback. if (e.type=='keyup' && e.keyCode!=8) return; // Check if timeout has been set. If it has, "reset" the clock and // start over again. if (timeoutReference) clearTimeout(timeoutReference); timeoutReference = setTimeout(function(){ // if we made it here, our timeout has elapsed. Fire the // callback doneTyping(el); }, timeout); }).on('blur',function(){ // If we can, fire the event since we're leaving the field doneTyping(el); }); }); } }); })(jQuery); $('#example').donetyping(function(){ $('#example-output').text('Event last fired @ ' + (new Date().toUTCString())); });[code]<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="example" /> <p id="example-output">Nothing yet</p>
方案2.
[b]https://github.com/kenshin54/jquery-koala[/b][/code]
Load jQuery and koala:
<script src="jquery.min.js" type="text/javascript"></script> <script src="jquery.koala.js" type="text/javascript"></script>
Bind keyboard events to the dom with Koala.
<script type="text/javascript"> jQuery(document).ready(function() { $('.koala').koala({ delay: 200, keyup: function(event){ // do anything you want // ex. ajax } }); }); </script>
Koala support descendant elements that are added to the document at a later time.
<script type="text/javascript"> jQuery(document).ready(function() { $("#future").koala('.koala', { delay: 300, keyup: function(event){ // do anything you want // ex. ajax } }); }); </script>
相关文章推荐
- 牛腩购物 8 整合用户留言 动软生成器 ,.NET在后置代码中输入JS提示语句(背景不会变白),repeater 循环的时候事件判断,repeater 隔行 奇数行,item列,隐藏区块 Panel 的使用,前台绑定代码的时候使用函数
- JS对输入判断变化屏蔽中文输入法输入时连续触发事件的方法
- js判断用户输入的内容是否为纯数字
- JS 对输入判断变化屏蔽中文输入法连续输入时触发的事件
- js判断用户输入是否是固定电话或者电话号码
- js 各类判断用户输入字符的格式函数
- js判断用户是输入的地址请求的路径(实例讲解)
- js中判断用户输入的值是否为空的简单实例
- 使用js判断用户输入日期的合法性
- js中利用isNaN函数判断用户输入是否为数字
- js判断用户输入了多少个字节?
- js 判断用户输入的密码强度
- JS判断两种格式的输入日期的正确性
- 偷来的js 判断用户关闭浏览器或者刷新页面 ie有效
- JS控制用户只能输入分数和小数,每次输入验证
- WinForm 中要求在textBox中输入的内容必须是日期格式yyyy-mm-dd,判断用户输入是否有效!
- 用js判断用户浏览器是否是XP SP2的IE6
- 假如你想输入一个用户姓名,那么如何用C#语言判断该姓名在数据库中是存在的呢?
- js 几种常用的表单输入判断