我有可折叠菜单的动态代码。我想在折叠菜单时更改图像 php可折叠菜单的动态代码:
if($levelAction=="Expand"){
echo '<li>';
echo '<a href="#" class="swap-menu"><img id="coll" src="images/collapsed.gif" hspace = "2"/>'.$B->getAttribute('TITLE').'</a>';
echo '<ul style="display:none;" class="sub-menu">';
$groupStarted =1;
}
这里是可折叠菜单的javascript:
$(function(){
$('.swap-menu').bind('click',function(){
$('.sub-menu').find("+ ul").slideUp(1);
$(this).find("+ ul").slideToggle("fast");
});
$('.direct-link').bind('click',function(){
if(!$(this).parents('.sub-menu').length){
$('.sub-menu').hide();
}
var $current=$(this).parent();
var id=parseInt($current.find('input:hidden[name=menu-id]').val());
var slider=$current.find('input:hidden[name=slider]').val();
var min=parseInt($current.find('input:hidden[name=min]').val());
var max=parseInt($current.find('input:hidden[name=max]').val());
button_clk(id, slider, min, max);
});
});
答案 0 :(得分:0)
使用addClass和removeClass切换css类并为类分配不同的图像。 使用您的代码检查here。
$(function(){
$('.swap-menu').bind('click',function(){
$('.sub-menu').find("+ ul").slideUp(1);
$(this).find("+ ul").slideToggle("fast");
$('.swap-menu').toggleClass('current');// here you need to create one css class .current and put image you want to display or switch. Make sure you have alternate image for swap-menu which will switch with the current class
});
$('.direct-link').bind('click',function(){
if(!$(this).parents('.sub-menu').length){
$('.sub-menu').hide();
}
var $current=$(this).parent();
var id=parseInt($current.find('input:hidden[name=menu-id]').val());
var slider=$current.find('input:hidden[name=slider]').val();
var min=parseInt($current.find('input:hidden[name=min]').val());
var max=parseInt($current.find('input:hidden[name=max]').val());
button_clk(id, slider, min, max);
});
});