久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從鍵盤上的字段中獲取文本,但延遲進一步輸入

Get text from field on keyup, but with delay for further typing(從鍵盤上的字段中獲取文本,但延遲進一步輸入)
本文介紹了從鍵盤上的字段中獲取文本,但延遲進一步輸入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個在各種元素發生變化時遠程提交的表單.特別是在搜索字段上,我使用 keyup 來檢測字段中的文本何時更改.這樣做的問題是,當有人輸入chicken"時,表單會提交七次,只計算最后一次.

I have a form which is submitted remotely when the various elements change. On a search field in particular I'm using a keyup to detect when the text in the field changes. The problem with this is that when someone types "chicken" then the form is submitted seven times, with only the last one counting.

最好是這樣的

  • 檢測到按鍵 - 開始等待(一秒鐘)

  • keyup detected - start waiting (for one second)

檢測到另一個按鍵 - 重啟等待時間

another keyup detected - restart waiting time

等待完成 - 獲取值并提交表單

waiting finishes - get value and submit form

在我開始編寫我自己的版本之前(我真的是一個只有一點 js 的后端人員,我對所有事情都使用 jQuery),是否已經有一個現有的解決方案?這似乎是一個普遍的要求.也許是一個 jQuery 插件?如果不是,那么最簡單和最好的編碼方式是什么?

before I go off and code my own version of this (I'm really a backend guy with only a little js, I use jQuery for everything), is there already an existing solution to this? It seems like it would be a common requirement. A jQuery plugin maybe? If not, what's the simplest and best way to code this?

更新 - 為 Dan 添加的當前代碼(如下)

UPDATE - current code added for Dan (below)

Dan - 這可能是相關的.我在頁面上使用的其中一個 jQuery 插件(tablesorter)需要這個文件 - tablesorter/jquery-latest.js",如果包含該文件,則會導致您的代碼出現與以前相同的錯誤:

Dan - this may be relevant. One of the jQuery plugins I'm using on the page (tablesorter) requires this file - "tablesorter/jquery-latest.js", which, if included, leads to the same error with your code as before:

jQuery("input#search").data("timeout", null) 未定義http‍://192.168.0.234/javascripts/main.js?126408446711號線

jQuery("input#search").data("timeout", null) is undefined http‍://192.168.0.234/javascripts/main.js?1264084467 Line 11

也許不同的 jQuery 定義之間存在某種沖突?(或什么)

Maybe there's some sort of conflict between different jQuery definitions? (or something)

$(document).ready(function() {
  //initiate the shadowbox player
//  Shadowbox.init({
//    players:  ['html', 'iframe']
//  });
}); 

jQuery(function(){
  jQuery('input#search')
    .data('timeout', null)
    .keyup(function(){
      jQuery(this).data('timeout', setTimeout(function(){
          var mytext = jQuery('input#search').val();
          submitQuizForm();
          jQuery('input#search').next().html(mytext);
        }, 2000)
     )
     .keydown(function(){
       clearTimeout(jQuery(this).data('timeout'));
     });
    });
});

function submitQuizForm(){
  form = jQuery("#searchQuizzes");
  jQuery.ajax({
    async:true, 
    data:jQuery.param(form.serializeArray()), 
    dataType:'script', 
    type:'get', 
    url:'/millionaire/millionaire_quizzes',
    success: function(msg){ 
     // $("#chooseQuizMainTable").trigger("update"); 
    }
  }); 
  return true;
}

推薦答案

對不起,我還沒有測試過這個,它有點離我的頭,但是這些方面的東西應該可以解決問題.將 2000 更改為服務器帖子之間所需的毫秒數

Sorry i haven't tested this and it's a bit off the top of my head, but something along these lines should hopefully do the trick. Change the 2000 to however many milliseconds you need between server posts

<input type="text" id="mytextbox" style="border: 1px solid" />
<span></span>

<script language="javascript" type="text/javascript">
    jQuery(function(){
      jQuery('#mytextbox')
        .data('timeout', null)
        .keyup(function(){
            clearTimeout(jQuery(this).data('timeout'));
            jQuery(this).data('timeout', setTimeout(submitQuizForm, 2000));
        });
    });
</script>

這篇關于從鍵盤上的字段中獲取文本,但延遲進一步輸入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 久久日av| 久草手机在线视频 | 91av免费观看 | av毛片网站| 男女久久久 | 91性高潮久久久久久久久 | 亚洲欧美在线视频 | 国产亚洲视频在线观看 | 一区二区三区在线观看免费 | 九九热在线精品视频 | 日韩在线网址 | 免费在线看黄网站 | 亚洲香蕉视频 | 国产欧美日韩在线 | 欧美黄色一级大片 | 一级黄色免费视频 | 欧美日韩免费在线观看 | 免费黄色小网站 | 欧美成人小视频 | 成人在线视频播放 | 久视频在线 | 四虎在线免费视频 | 国产三级黄色 | 91午夜精品| 欧美一区二区在线 | 国产视频导航 | 99视频网站| 成人性生活片 | 国产欧美日韩在线观看 | 欧美日韩精品一区二区在线播放 | 不卡的av| 欧美成人精品一区二区 | 中文字幕一级片 | 一级黄色大片 | 成人在线小视频 | 久久免费看| 91精品国自产在线观看 | 中文字幕免费在线观看 | 欧美一区二区三区在线观看 | 精品在线一区 | 久久色av |