简体   繁体   English

Javascript:自动点击按钮?

[英]Javascript: Automatically clicking a button?

I'm learning how to write a chrome extension, and I'm fairly new to javascript.我正在学习如何编写 chrome 扩展程序,而且我对 javascript 还很陌生。

Here's some html:这是一些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>

What I want to do is open link2.com by automatically clicking button2 using javascript.我想要做的是通过使用 javascript 自动单击 button2 来打开 link2.com。

I'm using the following, but it's not working :/我正在使用以下内容,但它不起作用:/

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

Any help would be appreciated!!任何帮助,将不胜感激!!

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

您需要选择索引,因为 getElementsByClassName 返回数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM