indexOf在JavaScript中不起作用 [英] indexOf is not working in JavaScript
本文介绍了indexOf在JavaScript中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查JAVASCRIPT中字符串的索引.这是错误的.该值属于哪个位置,如下所示:
I am checking an index Of string in JAVASCRIPT. and this is coming as false. where as the value does belong to it as below :
if(idOfControl.indexOf(idOfButton)) == is giving false for the below values.
idOfControl = "dlInventory_btnEditComment_0"
idOfButton = "dlInventory_btnEditComment"
但是如果我运行idOfControl.replace(idOfButton, "");
,它可以正常工作并替换文本.
But if I run idOfControl.replace(idOfButton, "");
It is working and replacing the text.
任何原因吗?
推荐答案
indexOf
也可以返回0. 0
评估为false
.试试:
indexOf
can also return 0, in the event of your string being found at the position 0
. 0
evaluates to false
. Try:
if(idOfControl.indexOf(idOfButton) > -1)
更多信息: 查看全文