所以,我有代码,没有完成,但我想要它做的只是显示一个警告框,如果我写“帮助”,并说出其他任何其他输入.
function prompter() { var reply = prompt("This script is made to help you learn about new bands,to view more info,type help,otherwise,just click OK") if (reply === 'help' || 'Help') { alert("This script helps you find new bands. It was originally written in Python 3.0.1,using Komodo IDE,but was then manually translated into Javascript. Please answer the questions honestly. If you have no opinion on a question,merely press OK without typing anything.") } else { alert("Press OK to continue") } };
但是,无论如何,即使您按下取消,第一个警报框也会弹出
我应该怎么解决这个???
解决方法
if (reply === 'help' || 'Help')
应该:
if (reply === 'help' || reply === 'Help')
由于’帮助’是“真实的”,因此将始终输入if的第一部分.
当然,更好的做法是进行不区分大小写的比较:
if (reply.toLowerCase() === 'help')