0
<span id="continue" class="a-button a-button-span12 a-button-primary"><span class="a-button-inner"><input id="continue" tabindex="5" class="a-button-input" type="submit" aria-labelledby="continue-announce"><span id="continue-announce" class="a-button-text" aria-hidden="true">
          Continue
        </span></span></span>

在页面部分的 HTML 上方,该页面有一个我试图点击的“继续”按钮,使用我的脚本。

所以,用 Javascript 编写,我试图点击这个按钮。但我没有尝试过任何工作。

我尝试的答案是:

function() {


      var goButton = document.getElementById("continue");
     goButton.click();},

为什么它不起作用?请帮帮我 !

4

1 回答 1

1

您已将跨度和输入字段的 ID 设置为“继续”。ID 对于单个元素应该是唯一的。当我在浏览器的控制台中输入您的代码时,它会返回以下内容:

> var goButton = document.getElementById("continue");
< undefined
> goButton.valueOf()
< <span id="continue" class="a-button a-button-span12 a-button-primary">

您可以看到 span 是被选中的元素,而不是输入提交按钮。您应该重命名这两个元素中的任何一个,以便它们都有一个唯一的 ID 并在您的脚本中使用它。

编辑:OP提到HTML不能更改,因此可以使用此Javascript而不是修复使用非唯一ID:

function() { 
  var continueSpan = document.getElementById("continue"); 
  var goButton = continueSpan.firstElementChild.firstElementChild; 
  goButton.click();}
于 2017-11-20T16:12:29.920 回答