简体   繁体   English

如何模拟点击下拉列表?

[英]How to simulate click on dropdown list?

Here is Google registration page . 这是Google注册页面 There is a dropdown list. 有一个下拉列表。 How to simulate click on it using jQuery? 如何使用jQuery模拟点击? My code doesn't work. 我的代码不起作用。

$('#Gender').click()

在此处输入图片说明

PS I am wiritng userscript for another google website and there are same dropdowns. PS我wiritng userscript另一个谷歌网站,并有相同的下拉菜单。 So I don't want to make a script for autoregistration, don't worry. 因此,我不想为自动注册编写脚本,不用担心。

尝试$('#Gender').trigger("click");

You can do it with HTML + javascript, but it works only on Chrome. 您可以使用HTML + javascript来做到这一点,但仅适用于Chrome。

Check this Stack Overflow answer . 检查此堆栈溢出答案

By looking your screenshot it appear that it is not a real dropdown (ie select tag) . 通过查看您的屏幕截图,它似乎不是真正的下拉列表(即select标记)。

I believe your are using kendodropdown or jquery UI combobox or etc . 我相信您正在使用kendodropdown或jquery UI组合框等。

it change the dropdown to span,textbox combination and also change the id. 它将下拉列表更改为span,textbox组合,还更改了id。 To fire click event first inspect the element ,then bind it using the actual generated id or you can use class to bind the event . 要触发click事件,请先检查该元素,然后使用实际生成的ID绑定该元素,也可以使用class绑定该事件。

if this doesn't help you provide html and javascript . 如果这不能帮助您提供html和javascript。

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

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