索引不工作?
我这样做是为了只提交以“/msg”或“/logout”开头的消息。
但是,用户仍然可以发送消息!我的代码有问题吗?
if ((msg.indexOf("/msg") != 0) && (msg.indexOf("/logout") != 0))
{
return;
}
I made this so only messages starting with '/msg' or '/logout' will submit.
But, users can still send messages! Is something wrong with my code?
if ((msg.indexOf("/msg") != 0) && (msg.indexOf("/logout") != 0))
{
return;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
indexOf
<如果找不到String
, /a> 将返回 -1,否则它将返回找到的索引,即 >= 0所以你的测试必须是:
或
indexOf
will return -1 if theString
is not found otherwise it will return the index found which is >= 0So your test have to be:
or
事实证明我的代码确实有效。问题出在代码中,我忽略了向您展示,但我修复了它。
不管怎样,谢谢你的帮助。 :)
Turns out my code did work. The issue was in code I neglected to show you but I fixed it.
Thanks for the help anyway. :)