zl程序教程

您现在的位置是:首页 >  后端

当前栏目

一个封装js代码-----展开收起效果示例

JS封装代码 一个 示例 效果 展开 -----
2023-06-13 09:15:02 时间
第一次靠自己完整的封装的小特效,有点小小的兴奋,和大家分享下,希望能对和我一样在探索的童鞋们有点帮助
js部分:
复制代码代码如下:

varshow_obj=function(obj,at,ob){
$(obj).bind("click",function(){
varshowTxt=$(this).children(at);
//alert($(at).html());
//alert(sObj);
//alert();
//alert($(this).parent().children(p).html());
if(showTxt.html()=="+"){
showTxt.html("-")
}else{
showTxt.html("+")
}
$(this).parent().children(ob).slideToggle(300);
})
}

html引用:
复制代码代码如下:

$(function(){
show_obj(".slide_show",".slide_showa",".p-silde");
})
html代码:
<ul>
<li>
<divclass="clearfixslide_show"><spanstyle="float:left">我有列表</span><astyle="float:right">+</a></div>
<pclass="p-silde"style="display:none">
<ahref="#">列表1</a>
<ahref="#">列表2</a>
<ahref="#">列表3</a>
</p>
</li>
<li>
<divclass="clearfixslide_show"><spanstyle="float:left">我有列表</span><astyle="float:right">+</a></div>
<pclass="p-silde"style="display:none">
<ahref="#">列表1</a>
<ahref="#">列表2</a>
<ahref="#">列表3</a>
</p>
</li>
<li>
<divclass="clearfixslide_show"><span>我没有列表</span></div>
</li>
</ul>

PS:记住引用jQuery的框架,兼容ie6以上,火狐,谷歌,ie6没有测试大家可以自己测试