“UserInput”是用户输入的内容
用户会说你好_______
例如这里:我们将使用 Hello World
var input = UserInput;
// Let's say the user inputs hello world
if(input == "hello") {
var cut = input.substr(6)
console.log(cut)
}
用户正在输入“hello world”,但 if 语句不会接收到它
我的目标是从 if 语句中获取用户输入,但是有了它,我就可以替换他们所说的部分内容
最佳答案
使用string.indexOf
查看一个字符串是否包含另一个字符串
var input = UserInput;
// Let's say the user inputs hello world
if ( input.indexOf( "hello" ) != -1 ) {
var cut = input.substr(6)
console.log(cut)
}
注意使用这种方式区分大小写
关于javascript - 一种获得完整字符串的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700533/