我正在为产品开发一个类别。我想要实现的只是单击一个类别,然后这个当前类别背景会改变。它就像普通类别一样简单。但是,我正在努力实现它。谁能帮我解决这个棘手的问题?
下面是生成类别的代码
while ( $cat = mysql_fetch_assoc( $res ) )
{
$cats[] = $cat;
}
}
$list_items = array();
foreach ( $cats as $cat )
{
if ( ( int ) $cat['parent'] !== ( int ) $parent )
{
continue;
}
$current = $cat['categoryID'];
$list_items[] = '<nav><li class ="heading">';
$list_items[] = '<a href="javascript:void(0)" id ='. $cat['categoryID'].' onClick="getPage('. $cat['categoryID'] . ','.$cat['parent'].')">';
$list_items[] = $cat['name'];
$list_items[] = '</a></li>';
$list_items[] = '<ul class ="content">';
$list_items[] = category_list( $cat['categoryID'] );
$list_items[] = '</ul>';
$list_items[] = '</nav>';
$list_items[] = '';
}
$list_items = implode( '', $list_items );
if ( '' == trim( $list_items ) )
{
return '';
}
return '<div><ul>' . $list_items . '</ul></div>';
我目前对此的查询如下:
jQuery(document).ready(function() {
jQuery(".content").hide();
jQuery(".heading").click(function()
{
jQuery(this).next(".content").slideToggle(500,function(){
$(this).parent().find('li.heading').css('background-color','green');
$(this).find('.heading').css('background-color','red');
});
});
});
HTML:
<div class="catbottom">
<?php include("category.php");echo category_list();?>
</div>
非常感谢。
过程如下:
在 html 中,我包含用于生成类别的 category.php。
对于每个类别,当用户单击类别列表时,相应的项目将显示在一个名为“容器”的 div 中