Home > Article > Web Front-end > Dynamic fuzzy query based on input
This time I will bring you dynamic fuzzy query based on input. What are the precautions for dynamic fuzzy query based on input? The following is a practical case, let's take a look.
Recently when I was using jQuery to implement dynamic fuzzy query, I searched for a long time but could not find a dynamic fuzzy query method as easy to use as the watch attribute of Vue.js. Let me share the pitfalls encountered so far and several ways to implement dynamic query.
1.jQuery’s change() method.
This method will only be triggered when the focus of the input box is lost. The event feels a bit tasteless. It may also be that I am not fully familiar with using this. Method, I hope someone who knows it can share some tips on how to use it.
<input type="text" id="n3"/> var $n3=$("#n3);//定位到input框 $n3.change(function(){ this.query_search($n3.val());//query_search为模糊查询的方法 })
change()Function is used to bind a handler function to the change event of each matching element. This function can also be used to trigger change events. In addition, you can also pass some additional data to the Event Handling function. The change event is triggered when the text content or options are changed. This event only applies to and
2. Monitor JQuery's keyup or keydown event
This method can monitor the trigger event of each key and bind the fuzzy query method to Targeting the response event, each click will trigger a fuzzy query event, but this will greatly increase the pressure on the database. If there are many people operating and there is no cache, the database will explode in minutes.
<input type="text" id="#n3"/> var $n3=$("#n3");//定位到input框 $n3.keyup(function(){ this.query_search($n3.prop("value"));//query_search为模糊查询的方法 })
3. Use the watch attribute observer method of Vue.js.
This method can dynamically observe the changes in attributes in the input box. As long as the value of the input box changes, the corresponding method will be called dynamically.
##Worth it in the end What I said is that there are three ways to get the value in the input text box.
1. Get it through attr("value"). This method can only obtain the default one. In other words, the value originally defined in your CSS code will be the same value when the page is displayed for the first time, and this value will not change. 2. Obtain through prop("value"). This method can get the default value, as well as the changed or value. You can get it as long as you change it. 3. Obtain through val(). This feels similar to prop("value"). 4. You can also use the v-model binding of Vue.js to obtain it, so there are 4 methods. These are just the conclusions drawn by individuals through multiple tests. There is no authoritative statement. If there are any mistakes, I hope someone can correct them in time. I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:How to get the value of transform with jquery
How to request and wait for multiple AJAX requests together
Disable bottom page sliding under pop-up windows
The above is the detailed content of Dynamic fuzzy query based on input. For more information, please follow other related articles on the PHP Chinese website!