【问题标题】:Replace several input values替换几个输入值
【发布时间】:2014-03-25 06:56:03
【问题描述】:

我为我正在开发的一个小型聊天系统提供了这个功能。当用户在一些文本前键入“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
}

谢谢!

【问题讨论】:

  • 您正在测试 shout,但要替换 setimg
  • 错字,对不起@MikeW,应该改正。

标签: jquery input replace


【解决方案1】:

试试

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

【讨论】:

    猜你喜欢
    • 2012-07-30
    • 1970-01-01
    • 2014-04-18
    • 2011-05-19
    • 2014-05-04
    • 1970-01-01
    • 2019-11-24
    • 2014-01-17
    • 2019-11-25
    相关资源
    最近更新 更多