替换几个输入值

我有这个函数用于我正在进行的小型聊天系统。 当用户键入“shout”前面有一些文本时(例如:“shout hello!”)。 我只想要“你好!” 输出(其余应该被忽略)。 当我只有一个命令时,这很好用。 但现在我有“喊”和“消息”。 我尝试用下面的代码做一些事情,但它似乎不起作用:

function checkValue() { var value = document.getElementById("thisinput").value; // output text without "message" in front if (value == "message") { $('#output').html(value.replace('message', '')); } // output text without "shout" in front else if (value == "shout") { $('#output').html(value.replace('shout', '')); } // output nothing } 

谢谢!

尝试

 if(value.indexOf("message") != -1)