0

我正在尝试在页面加载时触发点击事件,但它似乎不起作用..

我在 Firebug 控制台中看不到任何错误...

查询:

jQuery(document).ready(function($) {
    $(window).load(function(){
      alert("Loaded.");
      $('.a-category .active').trigger('click'); 
    });
});

我添加警报只是为了检查它是否有效。它确实提醒..

任何帮助将不胜感激!

4

2 回答 2

1

你可能想要:

$('.a-category.active').trigger('click');

由于 html 是

<div class="a-category active">Websites</div>

侦听器应该同时存在于同一个类中div

目前,您正在使用 classactive的节点的子/孙节点中寻找类a-category,因此不会触发“点击”。

于 2013-06-18T18:31:02.613 回答
0

This code is correct

$(document).ready(function() {
    alert("Loaded.");
    $('.a-category .active').trigger('click'); 
});

if that doesn't work, your selector (the '.a-categry .active') might be incorrect. are you trying to select an element with both classes, or one inside the other?

you can also just call $('.a-category').click(); on an element, which will trigger the click on it

于 2013-06-18T18:34:17.590 回答