javascript - search() method
高洛峰
高洛峰 2017-05-18 11:03:10
0
2
1079

Baidu Front-End Academy Second Phase Task 20
http://ife.baidu.com/2016/tas...

search.addEventListener("click",function(){
               let text = searchText.value;//text 用户输入的内容

               for(let i= 0;i<data.length;i++){              

                    if(data[i].search(text)===0){

                          li[i].style.backgroundColor = "yellow";

                    }

               }
});

I saw someone matching the content input by the query user like this. I don’t know what this means. Is it a query for a string that is equal to 0?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
迷茫

Loop through all data数组,假如有data的元素没有找到text if(data[i].search(text)===0)、就把当前liSet the background to yellow warning!

淡淡烟草味

For details, please click on the js search method: http://www.w3school.com.cn/js...

JS search method: If no matching substring is found, it returns -1; if it is found, it returns the pattern matching template where the first letter of the string to be searched is located ->data[i] in the string Mark index.

So the if() judgment is to hope that text can be matched from the first letter of data[i].

Such as abacab.search(ab), this will return 0 and enter the if block.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template