Javascript 对象旁边的下拉菜单图像

Javascript 对象旁边的下拉菜单图像,javascript,jquery,Javascript,Jquery,我有一个下拉菜单,在链接旁边有由javascript生成的“+”和“-”,现在是我的问题。如何更改自定义图像上的“+”和“-”?“+”表示菜单关闭,“-”表示菜单展开。以下是代码: $(function() { // hide all the sub-menus $("span.toggle").next().hide(); $(".current").parents("li ul").show(); // add a link nudging animation effect to eac

我有一个下拉菜单,在链接旁边有由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 ) );
});
});

是否使用图像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'
        })
    )
};
if($(this).next().find(“.current”).html()!=null){
$(此)。预结束(
$('').attr({
“src”:“减.gif”,
“alt”:”,
‘高度’:‘25’
})
)
};

编辑:我刚刚注意到您检查了html子字符串1中的
+
-
。你可以在上面的图像中添加一个id属性,然后检查元素的长度。

我还需要所有链接的图像,但只显示“当前”:)嗯,我没有自己创建下拉菜单,所以我不知道如何正确编辑代码:p