0

次のjqueryを使用してドロップダウンメニューを作成しています:

$(document).ready(function(){
    // executed after the page has finished loading
   $('#navigationMenu li .normalMenu').each(function(
      $(this).before($(this).clone().removeClass().addClass('hoverMenu'));
   });
   $('#navigationMenu li').hover(function(){    
      $(this).find('.hoverMenu').stop().animate({marginTop:'0px'},200)
   },
   function(){
     $(this).find('.hoverMenu').stop().animate({marginTop:'-25px'},200);
   });
});

作成されたクローンのみから href を追加するのに助けが必要です。

4

2 に答える 2

0

を使用してクローンを作成するときに href を削除できます.removeAttr()

  $(this).before($(this).clone().removeClass().addClass('hoverMenu').removeAttr('href'));

href を追加するには、 .attr() を使用できます

 $(this).before($(this).clone().removeClass().addClass('hoverMenu').attr('href','#'));
于 2013-10-17T12:23:07.093 に答える
0

href属性を追加するには、次を使用しattrます。

$(this).before(
   $(this)
    .clone()
    .addClass('hoverMenu')
    .attr('href', 'http://google.com')
);

参照:

.attr( attributeName, value )


説明: 一致した要素のセットに 1 つ以上の属性を設定します。

  • attributeName

    タイプ:String

    設定する属性の名前。

  • value

    タイプ: 文字列または数値

    属性に設定する値。

于 2013-10-17T12:23:20.923 に答える