簡體   English   中英

Javascript:自動點擊按鈕?

[英]Javascript: Automatically clicking a button?

我正在學習如何編寫 chrome 擴展程序,而且我對 javascript 還很陌生。

這是一些html:

<div class="button data" style="">
   <a class="button1 whiteColor" href="http://link1.com">VIEW This</a>
   <a class="button2 redColor" href="http://link2.com">VIEW That</a>
</div>

我想要做的是通過使用 javascript 自動單擊 button2 來打開 link2.com。

我正在使用以下內容,但它不起作用:/

document.getElementByClassName("button2 redColor").click();

任何幫助,將不勝感激!!

document.getElementsByClassName("button2 redColor")[0].click();

您需要選擇索引,因為 getElementsByClassName 返回數組

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM