Use select2 plugin ()
Search through all the options values for this $ selectstring variable And then selects people if it is discovered at more than 200 option values, it takes about 5-6 seconds ... I'm trying to reduce it.
Is there a way to speed up the search element with string code?
jquery:
$ ('# selectbutton') ). Click (function () {var selectstring = $ ('# selectstring '). Val (); if (! Selectstring.trim ()) return false; stringVal.push ($ (' # projadd \\ [\\] '():' (': (': '(' included in ('' Selectstring + '' ')) {stringVal.push ($ (this) .val ());} $ (' # projadd \\ [\\] '). Val (stringVal) .trigger ("change "); $ ('# Selectstring'). Val ('');});
There is no problem here .each ()
but your code in general is not creating your code when you do not need it, when you want to exclude it out Are So you are specifying the value several times in each element.
When you can easily vanilla it, try to avoid jQuery, try to avoid :
Because it is an expensive selector.
Go through code that looks like this:
$ ('# selectbutton'). Click (function () { Var selectstring = document.getElementById ('selectstring'). Value; // Function reduces the number of calls and does not create any jQuery objects. If (! Selectstring.trim ()) return false; Var $ projadd = $ ('# projadd \\ [\\]'); // Do you use it more than 1 time? Cache this stringVal.push ($ projadd.val ()); $ Projadd.find ('Options'). Do not use every (function (if (this.TextContent.indexOf (selectstring)> gt; -1: Use the original javascript methods stringwhole pishoot (this.value); // not create jquery objects, properties Access attribute properties is always faster than calling a function.}}; $ Projadd.val (stringVal). Triggers ("change"); // eject it .each, you only set one time value Required. Document.getElementById ('selectstring'). Value = ''; // ea above the same R Son});
No comments:
Post a Comment