触发点击不起作用 [英] Trigger click not working

查看:124
本文介绍了触发点击不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:
非常感谢你所有的努力,现在我所有的代码都运行了!



我想触发 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事件不会打开 select 选项列表。



请参阅是否可以使用JS打开一个HTML选择来显示它的选项列表?



你可以测试它的工作原理通过为该元素添加您自己的 onclick 事件,然后触发点击事件。


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?

setTimeout(function () {
   $('select.product-type.js-size-type').trigger('click');
}, 1000);

This is the select button:

<select class="product-type js-size-type">

This is what chrome console says

caught TypeError: Cannot read property 'click' of null
    at <anonymous>:2:41

Updated:

My manifest of the chrome extension:

{
  "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
  }
}

YeezyCopper.js :

setTimeout(function () {
   $('select.product-type.js-size-type').trigger('click');
}, 1000);

Thanks in advance!

解决方案

The code works properly, but the "click" event triggered programmatically will not open the select option list.

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 onclick event for that element and then triggering the click event.

这篇关于触发点击不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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