【发布时间】:2010-07-08 16:47:20
【问题描述】:
我有两个独立的 jQuery 函数,允许用户切换 div 的可见性。默认情况下,div 将处于关闭状态。我正在尝试找出一种方法来设置指向此页面的链接,该链接将根据传递给查询字符串的 ID 打开特定的 div。我的 jQuery 看起来像这样:
jQuery(document).ready(function(){
//make first div always open
jQuery(".toggle_container:not(:first)").hide();
jQuery(".toggle_container:first").show();
jQuery("h6.trigger:first").addClass("active");
jQuery("h6.trigger").click(function(){
jQuery(this).toggleClass("active");
jQuery(this).next(".toggle_container").slideToggle(300);
});
//The second function
jQuery(function(){
jQuery(".toggleIt").click(function(){
jQuery(this).next(".hiddenText").slideToggle("fast");
jQuery(this).html(function(i,html) {
if (html.indexOf('+') != -1 ){
html = html.replace('+','-');
} else {
html = html.replace('-','+');
}
return html;
})
});
});
HTML
<h6 class="trigger" id='uniqueID"></h6>
<div class="toggle_container">
TEST
</div>
//and the second toggled container
<p class="toggleThis tips" id="AnotherID">+</p>
<div class="hiddenText2">
Another TEST
</div>
我想在 url 的查询字符串中添加一个 ID,并让它打开具有相同 ID 的隐藏 div。到目前为止,我的结构是这样的......
var category = getParameterByName('cat');
var id = getParameterByName('id');
if(id)
{
}
else if(category)
{
}
else
{
//moving this in here
jQuery(".toggle_container:not(:first)").hide();
jQuery(".toggle_container:first").show();
jQuery("h6.trigger:first").addClass("active");
}
我在这部分卡住了。有小费吗?
【问题讨论】: