gpt4 book ai didi

javascript - JS问题中在字符串中搜索字符串

转载 作者:行者123 更新时间:2023-11-28 09:35:51 25 4
gpt4 key购买 nike

我使用的是 HTML5,indexOf 给了我一个错误,那么我还能用什么来搜索字符串中的“正确”一词:a001_new_quiz_multiple_choice_new_mc4_correct.html它位于名为 value1 的变量中

function SetAPIValue(key1, value1)
{
// alert("action is " + key1 + " and data is " + value1);
console.log(value1);

var str = "wrong";
var n = str.search(value1);
if (n > 0)
alert("found");
}

我收到的错误:0x800a01b6 - Microsoft JScript 运行时错误:对象不支持属性或方法“indexOf”

最佳答案

我不知道你如何使用indexOf,但这有效:

var value1 = "a001_new_quiz_multiple_choice_new_mc4_correct.html";
var n = value1.indexOf("correct");
if (n >= 0) alert("found");

也许您尝试过 "Correct".indexOf(value1); 而不是 value1.indexOf("Correct");

demonstration

关于javascript - JS问题中在字符串中搜索字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13064242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com