替换几个输入值 [英] Replace several input values

查看:81
本文介绍了替换几个输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的小型聊天系统具有此功能.用户在键入"shout"之前键入一些文本时(例如:"shout hello!").我只想要你好!"输出(其余的应忽略).当我只有一个命令时,这很好用.但是现在我有大喊"和信息".我尝试使用下面的代码做某事,但是它似乎不起作用:

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
}

谢谢!

推荐答案

尝试

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

这篇关于替换几个输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆