在页面加载时我需要模拟标签上的点击,然后,当它被点击时我想要slideDown(); #commenter-info。
所以我正在寻找的是这样的:
if ($(this).attr('id') == 'true') {
$(this).trigger("click", function() {
$(this).closest('form').find('#commenter-info').slideDown();
});
}
如果id为“true”,请单击该链接,然后执行slideDown();
问题是“#commenter-info”会在点击事件中添加,而不会出现在页面加载中。
答案 0 :(得分:2)
您必须分两步完成。
if ($(this).attr('id') == 'true') {
// First set up the listener :
$(this).bind("click", function() {
$(this).closest('form').find('#commenter-info').slideDown();
});
// Then, fire the click event
$(this).click();
}