I have an jquery autosuggest plugin in which when i type ex. Korea
then it show 2 results i.e.
Korea (North)
& Korea (South)
but when i type Korea (
, its not displaying any result where it had to show both Korea (North)
& Korea (South)
.
After searching in the code for the error then i found a search()
function which search for the type str开发者_开发知识库ing in the results..
means:
Korea (
in Korea (North)
& Korea (South)
and i think this search function stops at bracket (
and i don't know why???
Please, suggest a search() function to remove this error..
code:::
str.search(query) != -1
where: str = one result at a time i.e. Korea (North)
query = entered string i.e. Korea (
The first parameter of search()
is treated a regular expression, and Korea (
is an invalid regular expression. This is why "Korea (North)".search("Korea (")
fails.
Use indexOf()
instead:
str.indexOf(query) != -1
search() is a regular expression function. The ( character has significant meaning in regular expression, hence why the search fails. If you escape the ( with a backslash it should work
str.search("Korea \(");
精彩评论