Home > Web Front-end > JS Tutorial > body text

Dynamic fuzzy query based on input

php中世界最好的语言
Release: 2018-03-15 15:38:42
Original
2100 people have browsed it

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为模糊查询的方法
})
Copy after login

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