Javascript:自动点击一个按钮? [英] Javascript: Automatically clicking a button?

查看:167
本文介绍了Javascript:自动点击一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是一些html:

 < div class =button datastyle => 
< a class =button1 whiteColorhref =http://link1.com> VIEW此< / a>
< a class =button2 redColorhref =http://link2.com> VIEW< / a>
< / div>

我想要做的是使用javascript自动点击button2来打开link2.com。



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

 文档。 getElementByClassName(button2 redColor)。click(); 

任何帮助我们都会感激!!

解决方案

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

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

I'm learning how to write a chrome extension, and I'm fairly new to javascript.

Here's some 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.

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();

You need select index, because getElementsByClassName return the array

这篇关于Javascript:自动点击一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆