English 中文(简体)
页: 1 search ja
原标题:jQuery search as you type with ajax
  • 时间:2012-04-25 15:14:14
  •  标签:
  • jquery

i m 试图进行搜索,如果你把案文输入一个文本领域,并用钥匙将其击落一个功能,把外地的价值送到一页,并将结果退回到散装箱。 问题一是,当有人打打打字时,就会有可怕的滞后。 我认为,正在做的是,它试图搜查每封信件,并且每次都这样做。 如何做到这样,如果箱子中的一型,如果箱子中不作任何分类,则要等待1/2次(500次),那么就进行亚克斯的搜索,但如果在那个时间框架内收到另一封信,甚至不会收到亚克斯的请求。 我已忙于此事,可以 figure。 一切帮助都值得赞赏。

// fired off on keyup
function findMember(s) {
    if(s.length>=3)
        $( #searchResults ).load( /search.asp?s= +s);
}
最佳回答

这样做是明确的,即每个新闻机构都要花时间,这样,如果一/2秒钟的 t子被击落,然后再为500名记者开一个时间。 这就不需要装设一个大型图书馆。

let timeoutID = null;

function findMember(str) {
  console.log( search:   + str)
}

$( #target ).keyup(function(e) {
  clearTimeout(timeoutID);
  const value = e.target.value
  timeoutID = setTimeout(() => findMember(value), 500)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="search" id="target" placeholder="Type something" />
问题回答

支离破碎的汽车具有这一特点。

。 http://jqueryui.com/demos/autocomplete/

如果你不希望利用 j,那么就看自己的来源代码。

function myFunction(inputText) {
                debugger;
                var inputText = document.myForm.textBox.value;

                var words = new Array();
                var suggestions = "Always", "azulejo", "to", "change", "an", "azo", "compound", "third"];
                if (inputText != "") {
                    for (var i = 0; i < suggestions.length; ++i) {
                        var j = -1;
                        var correct = 1;
                        while (correct == 1 && ++j < inputText.length) {
                            if (suggestions[i].toUpperCase().charAt(j) != inputText.toUpperCase().charAt(j)) correct = 0;
                        }
                        if (correct == 1) words[words.length] = suggestions[i];
                        document.getElementById("span1").innerHTML = words;

                    }
                }

                else {
                    document.getElementById("span1").innerHTML = "";

                }

<p id="demo"></p>
    <form name="myForm">
         <input type="text" name="textBox" onkeyup="myFunction()"/>
         <span id="span1"></span>
    </form>




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签