Replace several input values

谁说胖子不能爱 提交于 2020-01-24 19:29:47

问题


I have this function for a small chat system that I'm working on. When the users types "shout" preceded by some text (ex: "shout hello!"). I want only the "hello!" to output (the rest should be ignored). This worked fine when I only had one command. But now I have "shout" & "message". I tried doing something with the code below but it doesn't seem to work:

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
}

Thanks!


回答1:


try

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


来源:https://stackoverflow.com/questions/22622088/replace-several-input-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!