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 は、1 つの要素に対して一意である必要があります。ブラウザのコンソールにコードを入力すると、次のように返されます。

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

入力送信ボタンではなく、スパンが選択されている要素であることがわかります。2 つの要素のいずれかの名前を変更して、両方が一意の ID を持つようにし、それをスクリプトで使用する必要があります。

編集:OPはHTMLを変更できないと述べたので、一意ではないIDの使用を修正する代わりに、このJavascriptを使用できます:

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