JS Fuzzy Matching

Source: Internet
Author: User

<div> <input type= "text" placeholder= "Please enter ..." id= "input"/><button> search </button> <ul Id= "Inputinfo" ></ul> </div>Let search=[] Let list= ' 'varInputarr =[] document.getElementById (' input '). Oninput =function() { let that= ThisConsole.log (That.value)if(inputarr.length==0) {Inputarr.push (that.value)}Else{inputarr.indexof (that.value)==-1?inputarr.push (that.value): "Inputarr.length>10?inputarr.shift (): "        }        if(That.value = = "") {Search=[] document.getElementById (' Inputinfo '). InnerHTML = "        }Else{Let num= 0Search= []             for(Let i= 0;i<inputarr.length;i++){                if(Inputarr[i].indexof (That.value)!=-1) {Search.push (inputarr[i])}Else{num++                }            }            if(num==inputarr.length) {Search=[] document.getElementById (' Inputinfo '). InnerHTML = "            }Else{                 for(Let i = 0;i<search.length;i++) {List+ = ' <li> ' +search[i]+ ' </li> '} document.getElementById (' Inputinfo '). InnerHTML =List Search=[] List= ' '            }        }        //Add a Click eventLet lis = Document.queryselectorall (' #inputInfo li ')         for(Let i = 0;i<lis.length;i++) {Lis[i].onclick=function() {document.getElementById (' input '). Value = This. InnerHTML Search=[] List= ' 'document.getElementById (' Inputinfo '). InnerHTML =List}} }

Iviewui's fuzzy matching is not called hand, colleague modified a bit, but the feeling is still good trouble. But at present there is a well-read Vue so use JS combined with friends to write the topic to play.

JS Fuzzy Matching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.