jQuery自动点击问题
我编写了通过以下代码自动单击导航栏中的链接来响应图像开始单击的代码:
$('body.node-4 div#block-views-Poster-block_1 img.imagecache-Posters').addClass('manually-linking').click(
function(){
//$('body.node-4 div#block-menu-primary-links ul li a.menu-224').css('color', 'red').trigger('click');
$('body.node-4 div#block-menu-primary-links ul li a.menu-224').css('color', 'green').click();
}
);
在每种情况下, .trigger('click')
和 .click( )
,我通过 CSS 将颜色应用到目标链接。单击图像时,目标链接会改变颜色,但不会导航到相关页面。
我可能做错了什么?
I have written code which responds to an image begin clicked by auto clicking a link in the navigation bar by the following code:
$('body.node-4 div#block-views-Poster-block_1 img.imagecache-Posters').addClass('manually-linking').click(
function(){
//$('body.node-4 div#block-menu-primary-links ul li a.menu-224').css('color', 'red').trigger('click');
$('body.node-4 div#block-menu-primary-links ul li a.menu-224').css('color', 'green').click();
}
);
In each case, .trigger('click')
and .click()
, I am applying color via CSS to the target link. When the image is clicked, the target link changes color but the navigation to the relevant page never happens.
What might I be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单地重定向到该 URL,而不是实际触发点击不是更容易吗?
我假设您正在更改链接的颜色,只是为了确认它的目标正确(因为当页面重新加载时它当然会被重置)。
Wouldn't it be easier to simply redirect to that URL, instead of actually triggering the click?
I assume you are changing the colour of the link, merely to confirm that it targets properly (as it will of course be reset, when the page reloads).