jquery 选项卡效果 新手代码


jquery代码
复制代码 代码如下:

$(function(){
//选项卡
var $qqbind=$("#qq_1_1 ul li"); //获取要变化的标题为了设置它背景色变化
$qqbind.click(function(){
var ch=$qqbind.has("pre"); //去找带有pre这个标签的标题;pre是设置她的背景样式下面要用
ch.html(ch.children("pre").html()); //把带有pre标签的去掉
$(this).wrapInner("<pre></pre>"); //给当前得$qqbind的内容上包围<pre> 元素:

$("#tab_bx").children("div").removeClass("show123").addClass("hide123"); //找到id未tab_bx得div移除显示并隐藏
$("#div"+$(this).attr("name")).addClass("show123"); //找到div并把li中name得值赋给要显示的div
});

})

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
pre{margin: 0px;padding: 0px;background-color: #00CC33;height: 38px;width: 132px;float: left; background-color:#C90}
.show{display:inline; z-index:100;}
.hidde{display:none}
#qq_1 { float: left;height: auto;width: 770px;}
#qq_1 #qq_1_1 {height: 38px;width: 100%;}
#qq_1_1 ul {margin: 0px;padding: 0px;float: left;width: 100%;}
#qq_1_1 li { cursor:pointer; display: block;height: 38px;list-style-type: none;float: left;margin: 0px;padding: 0px;width: 132px;line-height: 38px;
text-align: center;font-size: 18px;font-family: "黑体";background-image: url(../images/0123_2.jpg);background-repeat: repeat-y;}

#qq_1 .qq_1_2 { float: left;height: 280px;width: 100%;border: 1px solid #CCCCCC;padding-top: 12px;font-size: 13px;padding-right: 0%;
padding-left: 0%; padding-bottom: 1px;}

</style>
<script language="javascript" type="text/javascript" src="JS/jquery-1.4.2.js"></script>
<script>
$(document).ready(function(){
var $qqbind=$("#qq_1_1 ul li"); //获取要变化的标题为了设置它背景色变化
$qqbind.click(function(){
var ch=$qqbind.has("pre");//去找带有pre这个标签的标题;pre是设置她的背景样式下面要用
ch.html(ch.children("pre").html()); //把带有pre标签的去掉
$(this).wrapInner("<pre></pre>");//给当前得$qqbind的内容上包围<pre> 元素:
$("#tab_bx").children("div").removeClass("show").addClass("hidde");");//找到id未tab_bx得div移除显示并隐藏
$("#div"+$(this).attr("name")).addClass("show");//找到div并把li中name得值赋给要显示的div
alert("#div"+$(this).attr("name"));
});
});
</script>
<title>测试</title>

</head>

<body>
<div id="qq_1_1">
<ul>
<li name="1">
<pre> QQ币充值</pre>
</li>
<li name="2"> 包月服务</li>
</ul>
</div>
<div id="tab_bx">
<div id="div1" class="show">QQ币页面</div>
<div id="div2" class="hidde">游戏页面</div>
</div>
</body>
</html>

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3