0

我的网页上有一个基本的 jQuery 脚本,它具有 div 隐藏/显示功能。

它工作得很好,但是,我注意到我在“隐藏”div ( .newboxes2) 中的链接没有按预期工作。我希望点击它们并被带到谷歌。

有人可以解释我如何更新我的代码来解决这个问题吗?

这是我的jsFiddle,希望能说明我的观点。

jQuery:

$(document).ready(function() {

 $('.showscroll').bind('click', 'h2, h3', function(e) {
   e.preventDefault();

   $(this).toggleClass('active');
   $(".newboxes2").not($(this).find(".newboxes2")).slideUp();
   $(this).find('.newboxes2').slideToggle();

               if($(this).is('.active') ) {
                       $(this).find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_onstate.png');
               } else {
                       $(this).find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png');
               }
   if (this.id === 'service29') {
    $('html, body').animate({
      scrollTop: $(this).find('h2').offset().top
    }, 1000);
                }

 });

});

谢谢 :-)

4

2 回答 2

2

你有e.preventDefault();你的jquery。这会阻止链接继续。

于 2013-02-03T15:39:33.420 回答
1

试试这个:- http://jsfiddle.net/fS5gq/9/

$(".ancClass").click(function (e) {
    window.location.href = $(this).attr("href");  
    return false;
});

我为锚标记添加了一个类,并添加了事件来处理重定向。

于 2013-02-03T15:55:14.077 回答