替换多个输入值

时间:2014-03-24 22:42:35

标签: jquery input replace

我有一个我正在处理的小型聊天系统的功能。当用户键入“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
}

谢谢!

1 个答案:

答案 0 :(得分:0)

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