[英]How can I “click” all divs in the firebug console?
How can I perform a "click" action on all the rows that start with "user_" in the following html: 如何在以下html中以“ user_”开头的所有行上执行“点击”操作:
<div id="rows">
<div id="user_1"></div>
<div id="user_2"></div>
<div id="user_3"></div>
<div id="user_4"></div>
</div>
jQuery('div[id^="user_"]').click();
假设“执行单击操作”是指“触发单击事件”,则可以使用属性starts-with选择器,以及不带参数的click
方法(等同于trigger("click")
):
$("div[id^='user_']").click();
$("div[id^=user_]").click();
You can paste that inside the Firebug console or just put it in your page as it is valid JavaScript either way. 您可以将其粘贴到Firebug控制台中,也可以将其放入页面中,因为这两种方式都是有效的JavaScript。
Selecting all elements with an attribute starting with some string: 选择具有以某些字符串开头的属性的所有元素:
$('div[id^="user_"]')
"Clicking" them: “点击”它们:
$('div[id^="user_"]').click();
However, you might want to add a class to them, which beats string matching on attributes. 但是,您可能想向它们添加一个类,该类优于属性上的字符串匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.