触发点击不起作用 [英] Trigger click not working
问题描述
非常感谢你所有的努力,现在我所有的代码都运行了!
我想触发 https://shop.adidas.ae/zh/stan-smith-shoes/S82255 .html (制作鞋子机器人)。
为什么此代码无法触发大小类型按钮?
setTimeout(function(){
$('select.product-type.js-size-type')。trigger('click');
},1000);
这是选择按钮:
< select class =product-type js-size-type>
这是Chrome控制台所说的
已捕获TypeError:无法在<匿名>:2:41>
更新:
我的Chrome扩展清单:
{
name:name,
description:test,
version: 1.0,
manifest_version:2,
permissions:[*:// * / *],
content_scripts:[
{
matches:[*://*.adidas.ae/*],
js:[jquery.js,yeezyCopper.js]
}
$ bbackground:{
scripts:[background.js],
persistent:false
}
}
YeezyCopper.js:
setTimeout(function(){
$('select.product-type.js-size-type')。trigger('click');
},1000);
提前致谢! 代码正常工作,但以编程方式触发的click事件不会打开 请参阅是否可以使用JS打开一个HTML选择来显示它的选项列表? 你可以测试它的工作原理通过为该元素添加您自己的 Edit:
Thank you so much for all the effort, got all my code running now! I want to trigger a click on https://shop.adidas.ae/en/stan-smith-shoes/S82255.html (to make a shoe bot).
Why does this code not work to trigger the size type button? This is the select button: This is what chrome console says Updated: My manifest of the chrome extension: YeezyCopper.js : Thanks in advance! The code works properly, but the "click" event triggered programmatically will not open the See Is it possible to use JS to open an HTML select to show its option list? You can test that it works by adding your own 这篇关于触发点击不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! select
选项列表。
onclick
事件,然后触发点击
事件。setTimeout(function () {
$('select.product-type.js-size-type').trigger('click');
}, 1000);
<select class="product-type js-size-type">
caught TypeError: Cannot read property 'click' of null
at <anonymous>:2:41
{
"name": "name",
"description": "test",
"version": "1.0",
"manifest_version": 2,
"permissions": ["*://*/*"],
"content_scripts": [
{
"matches": ["*://*.adidas.ae/*"],
"js": ["jquery.js", "yeezyCopper.js"]
}
],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
setTimeout(function () {
$('select.product-type.js-size-type').trigger('click');
}, 1000);
select
option list.onclick
event for that element and then triggering the click
event.