0

ドロップダウンメニューがあり、リンクの隣に「+」と「-」がjavascriptによって生成されており、これが私の質問です。カスタム イメージの "+" と "-" を変更するにはどうすればよいですか? 「+」はメニューが閉じているとき、「-」は展開されているときです。コードは次のとおりです。

$(function() {
// hide all the sub-menus
$("span.toggle").next().hide();
$(".current").parents("li ul").show();


// add a link nudging animation effect to each link
$("#jQ-menu a, #jQ-menu span.toggle").hover(function() {
    $(this).stop().animate( {
        //paddingLeft:"10px",
        color:getElementById("#jQ-menu a, #jQ-menu span.toggle").color
    }, 300);
}, function() {
    $(this).stop().animate( {
        paddingLeft:"0",
        color:getElementById("#jQ-menu a, #jQ-menu span.toggle").color,
    }, 300);
});
$("#jQ-menu li.current a").hover(function() {
    $(this).stop().animate( {
        //paddingLeft:"10px",
        color:getElementById("#jQ-menu li.current a").color
    }, 300);
}, function() {
    $(this).stop().animate( {
        paddingLeft:"0",
        color:getElementById("#jQ-menu li.current a").color,
    }, 300);
});

// set the cursor of the toggling span elements
$("span.toggle").css("cursor", "pointer");

// prepend a plus sign to signify that the sub-menus aren't expanded
$('span.toggle').each(function(){
  if($(this).next().find(".current").html() != null){
    $(this).prepend("- ");
  }else{
     $(this).prepend("+ ");
  };
            });
// add a click function that toggles the sub-menu when the corresponding
// span element is clicked
$("span.toggle").click(function() {

    $(this).next().toggle(1000);
        // switch the plus to a minus sign or vice-versa
        var v = $(this).html().substring( 0, 1 );
        if ( v == "+" ){
            $(this).html( "-" + $(this).html().substring( 1 ) );
            var li = $(this).parent().siblings('li');
            $('span.toggle', li).each(function(){
                var v = $(this).html().substring( 0, 1 );
                if ( v == "-" ){
                $(this).html( "+" + $(this).html().substring( 1 ) );
                $(this).next().toggle(1000);
                }
            });
        } else if ( v == "-" )
            $(this).html( "+" + $(this).html().substring( 1 ) );
});
});
4

1 に答える 1

0

画像の HTML マークアップを先頭に追加しますか?

if($(this).next().find(".current").html() != null){
    $(this).prepend(
        $('<img />').attr({
            'src': 'plus.gif',
            'alt': '', 
            'height': '25'
        })
    );
} else {
     $(this).prepend(
        $('<img />').attr({
            'src': 'minus.gif',
            'alt': '', 
            'height': '25'
        })
    )
};

+編集:またはの html 部分文字列 1 をチェックしていることに気付きました-。上記の画像に id 属性を追加して、要素の長さを確認するだけです。

于 2013-06-10T10:13:27.893 に答える