Javascript 如何使用ddaccordian.init使当前类别选项卡保持打开状态?
我有分类列表,一些有子分类,一些有子分类,它们是这样的:Javascript 如何使用ddaccordian.init使当前类别选项卡保持打开状态?,javascript,jquery,magento-1.5,magento,Javascript,Jquery,Magento 1.5,Magento,我有分类列表,一些有子分类,一些有子分类,它们是这样的: Main menu sub menu sub menu 我过去经常看开盘和收盘的比赛。一切正常,但现在我想要的是,当前选定的URL类别必须保持打开状态 我尝试了以下代码: <script type="text/javascript"> ddaccordion.init({ headerclass: "question", //Shared CSS class name of headers grou
Main menu
sub menu
sub menu
我过去经常看开盘和收盘的比赛。一切正常,但现在我想要的是,当前选定的URL类别必须保持打开状态
我尝试了以下代码:
<script type="text/javascript">
ddaccordion.init({
headerclass: "question", //Shared CSS class name of headers group
contentclass: "theanswer", //Shared CSS class name of contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
collapseprev: false, //Collapse previous content (so only one open at any time)? true/false
defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
animatedefault: false, //Should contents open by default be animated into view?
persiststate: false, //persist state of opened contents within browser session?
toggleclass: ["closedanswer", "openanswer"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
//togglehtml: ["prefix", "<img src='images/plus.gif' /> ", "<img src='images/minus.gif' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
oninit:function(expandedindices){ //custom code to run when headers have initalized
//do nothing
},
onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
//do nothing
}
})
</script>
ddaccordion.init({
headerclass:“问题”//头组的共享CSS类名
contentclass:“theanswer”,//内容组的共享CSS类名
revealtype:“click”//当用户在标题上单击或点击鼠标时显示内容?有效值:“click”、“clickgo”或“mouseover”
mouseoverdelay:200,//如果revealtype=“mouseover”,则在标头在mouseover上展开之前以毫秒为单位设置延迟
collapseprev:false,//折叠以前的内容(因此在任何时候只打开一个)?true/false
defaultexpanded:[],//默认打开的内容索引[index1、index2等].]表示没有内容。
onemustopen:false,//指定是否至少有一个标头应始终打开(因此从不关闭所有标头)
animatedefault:false,//默认情况下打开的内容是否应动画显示到视图中?
persiststate:false,//浏览器会话中打开内容的持久状态?
toggleclass:[“closedanswer”,“openanswer”],//两个CSS类,分别在头折叠和展开时应用于头[“class1”,“class2”]
//togglehtml:[“prefix”、“”、“”]、//在收拢和展开标题时分别向标题添加额外的HTML[“position”、“html1”、“html2]”(请参阅文档)
animatespeed:“快”//动画速度:以毫秒为单位的整数(即:200),或关键字“快”、“正常”或“慢”
oninit:function(expandedIndies){//头初始化时要运行的自定义代码
//无所事事
},
onopenclose:函数(头、索引、状态、isuseractivated){//在打开或关闭头时运行的自定义代码
//无所事事
}
})
为了激活当前类别,即必须保持打开状态,我执行了以下操作:
<a <?php if($_category->hasChildren()): ?>class="question"<?php endif; ?><?php if ($currentUrl == $this->getCategoryUrl($_category)): ?> class="current"<?php endif; ?> href="<?php echo $this->getCategoryUrl($_category) ?>">
<?php echo $_category['name']; ?>
</a>
<?php $potential1 = $_category->hasChildren(); ?>
<?php if($_category->hasChildren()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<ul <?php if($_subcategories): ?>class="theanswer"<?php endif; ?>>
<?php foreach($_subcategories as $subcat): ?>
<li>
<a <?php if($subcat->hasChildren()): ?>class="question"<?php endif; ?><?php if ($currentUrl == $this->getCategoryUrl($subcat)): ?> class="current"<?php endif; ?> href="<?php echo $this->getCategoryUrl($subcat); ?>">
<?php echo $subcat->getName(); ?>
</a>
<?php if($subcat->hasChildren()): ?>
<?php
$_subcat = Mage::getModel('catalog/category')->load($subcat->getId());
$childrens = $_subcat->getChildrenCategories();
?>
<ul <?php if($childrens): ?>class="theanswer"<?php endif; ?>>
<?php foreach($childrens as $_childrens): ?>
<li>
<a <?php if ($currentUrl == $this->getCategoryUrl($_childrens)): ?> class="current"<?php endif; ?>href="<?php echo $this->getCategoryUrl($_childrens); ?>">
<?php echo $_childrens->getName(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
>
>
但我在前端没有得到任何回应:(如果你认为我错过了foreach循环等,那没关系。我刚刚粘贴了部分代码,请告诉我哪里错了:(
尽管我正确地获取了当前URL。您选择的accordion插件似乎没有保持某个部分打开的选项,因此您必须自己拦截并停止该部分。它提供的唯一可能的事件是
onopenclose
,但该事件在完成后调用,这是无用的
你应该选择另一个满足你需要的插件
幸运的是,Magento已经提供了Prototype和它自己的accordion类,您可以替换它,或者单击它的
sectionClicked
方法并在那里停止事件
Accordion.prototype.sectionClicked = function(event) {
var element = $(Event.element(event)).up('.section');
if (!element.hasClassName('current')) {
this.openSection(element);
}
Event.stop(event);
};
这解决了我的问题,我所做的就是加上这个
而不是
if($currentUrl==this->getCategoryUrl($\u category)):?>
并在底部添加了Css类
<div class="content-links">
<ul>
<?php $i=0; foreach ($catlist as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a <?php if($_category->hasChildren()): ?>class="question"<?php endif; ?> href="<?php echo $this->getCategoryUrl($_category) ?>">
<?php echo $_category['name']; ?>
</a>
<?php $potential1 = $_category->hasChildren(); ?>
<?php if($_category->hasChildren()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<ul class="<?php if($_subcategories): ?>theanswer<?php endif; ?><?php //if($currentUrl == $this->getCategoryUrl($_category)): ?><?php if ($this->isCategoryActive($_category)): ?> opened<?php endif; ?>">
<?php foreach($_subcategories as $subcat): ?>
<li>
<a <?php if($subcat->hasChildren()): ?>class="question"<?php endif; ?> href="<?php echo $this->getCategoryUrl($subcat); ?>">
<?php echo $subcat->getName(); ?>
</a>
<?php if($subcat->hasChildren()): ?>
<?php
$_subcat = Mage::getModel('catalog/category')->load($subcat->getId());
$childrens = $_subcat->getChildrenCategories();
?>
<ul class="<?php if($childrens): ?>theanswer<?php endif; ?><?php if ($this->isCategoryActive($_subcat)): ?> opened<?php endif; ?>">
<?php foreach($childrens as $_childrens):
?>
<li>
<a <?php if ($currentUrl == $this->getCategoryUrl($_childrens)): ?>class="current"<?php endif; ?>href="<?php echo $this->getCategoryUrl($_childrens); ?>">
<?php echo $_childrens->getName(); ?>
</a>
</li>
<?php
endforeach;
echo "</ul>";
?>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</div>
</div>
<div class="clear" style="height:218px;"></div>
</div>
</div>
<div class="event-bot"></div>
</div>
</div> <!--inner right end here-->
<style type="text/css">
.opened { display:block !important;}
</style>
-