It's incorrect. search()
returns the offset position of a match if a match is found, and -1 if a match isn't found.
As you are checking for whether cate_no=24
contains cate_no=24
, it will return 0 if true.
Currently, your conditional checks whether the search()
will return > 0, which is not what you want.
What you should be doing is check whether it is greater > -1:
if (search_name.search("cate_no=24") > -1)
Although, as I mentioned in the first revision of my answer, it would be better and faster to use indexOf()
(search()
is supposed to be used when dealing with regular expressions, not for simple string searches).
if (search_name.indexOf("cate_no=24") > -1)