简体   繁体   English

chrome 控制台单击 function 在特定网站上什么也不做

[英]chrome console click function does nothing on a paritcular website

I went to this website我去了这个网站

http://getlike.io

and i wanted to do a simple click using the chrome console on that blue button top我想用那个蓝色按钮顶部的 chrome 控制台做一个简单的点击

在此处输入图像描述

I used chrome console and I right clicked on the element > inspect > found element on chromes console > copy selector and I got the selector.我使用了 chrome 控制台,然后右键单击元素 > 检查 > 在 chrome 控制台上找到元素 > 复制选择器,然后我得到了选择器。 Here is the selector for the blue button #header > div.top > div > div > div.col-md-2.col-3 > a这是蓝色按钮的选择器#header > div.top > div > div > div.col-md-2.col-3 > a

I just add it to a jquery tag since jquery is already loaded $("#header > div.top > div > div > div.col-md-2.col-3 > a").click();我只是将它添加到 jquery 标记,因为 jquery 已经加载$("#header > div.top > div > div > div.col-md-2.col-3 > a").click();

and it does nothing i have tried using javascript as well and still click does nothing..the odd thing is I am always using same way to click with console and it always works but this website..seems like they somehow understand i am performing click action using chrome console?它什么也没做我也尝试过使用 javascript 并且仍然单击什么也不做..奇怪的是我总是使用相同的方式点击控制台并且它总是有效但是这个网站..似乎他们以某种方式理解我正在执行点击使用 chrome 控制台的操作? does anyone knows why on this website not possible to click on some elements?有谁知道为什么在这个网站上无法点击某些元素?

I think it's because it's a <a> tag that doesn't have a click event attached to it.我认为这是因为它是一个没有附加点击事件的<a>标签。 On a button, there is usually a method linked with onClick or addEventListener or $.on("click") that is triggered when you click or use the .click() .在按钮上,通常有一个与onClickaddEventListener$.on("click")链接的方法,当您单击或使用 .click( .click()时会触发该方法。

If you look in the dev console, in the event listener of that element, there is nothing attached to it.如果您查看开发控制台,则在该元素的事件侦听器中,没有任何附加内容。

The return value of the Jquery selector is an array. Jquery 选择器的返回值是一个数组。 So you have to use the index to point to the item you want to work with.因此,您必须使用索引来指向您要使用的项目。

In this case, because there is only one item with the specified selector, you can use 0 index to access the button in the array.在这种情况下,由于指定选择器只有一项,因此可以使用 0 索引来访问数组中的按钮。

$("#header > div.top > div > div > div.col-md-2.col-3 > a")[0].click()

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

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