javascript - innerHTML 上的错误分配替换

标签 javascript variable-assignment innerhtml

我以前从来没有用 Javascript 做过任何事情,在试图用 tampermonkey 制作一个 chrome 用户脚本之后我似乎无法完成这个 Action ......这个功能工作得很好,但是当我这样做时我一直收到错误的分配或没有错误,但操作不会通过...这可能看起来非常丑陋或糟糕,但关于如何根据文本是否为 25-1

感谢任何能提供帮助的人。

function W01() 
{       
if (/another 25 seconds before attempting to search again/i.test (document.body.innerHTML) )
{
    document.body.innerHTML() = document.body.innerHTML.replace('Sorry, but you can only perform one search every 25 seconds. Please wait another 25 seconds before attempting to search again.', 'Press F5 or Reload the page now');
}
else if (/another 24 seconds before attempting to search again/i.test (document.body.innerHTML) )
{
    document.body.innerHTML() = document.body.innerHTML.replace('Sorry, but you can only perform one search every 25 seconds. Please wait another 24 seconds before attempting to search again.', 'Press F5 or Reload the page now');
}
    else if (/another 23 seconds before attempting to search again/i.test (document.body.innerHTML) )
    {
        document.body.innerHTML() = document.body.innerHTML.replace('Sorry, but you can only perform one search every 25 seconds. Please wait another 23 seconds before attempting to search again.', 'Press F5 or Reload the page now');
    }
}

最佳答案

删除innerHTML()中的()

应该是:

document.body.innerHTML = "some HTML";

请注意,它不是函数。这是一个属性。

例如这样做:

document.body.innerHTML = document.body.innerHTML.replace('Sorry, but you can only perform one search every 25 seconds. Please wait another 23 seconds before attempting to search again.', 'Press F5 or Reload the page now');

关于javascript - innerHTML 上的错误分配替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22914040/

相关文章:

javascript - 尝试对动态 HTML 表格列的值求和

javascript - 如何避免在 React Native 中重新渲染?

c++ - 为什么 C 和 C++ 支持在结构中按成员分配数组,但通常不支持?

javascript - 点击后警报按钮的内部内容

javascript - 将字符串传递给 innerHTML

javascript - 在 Windows 上使用 node.js 参数运行 grunt 任务

javascript - JavaScript 'bind' 方法有什么用?

variable-assignment - 如何从 VHDL 中的内部架构写入两个输出端口?

c - 传递 C 字符串并将其与本地指针一起使用

c# - Visual Web Developer 用新的 HTML 替换内部 HTML