jq实现切换tab

<html>
<head>
    <title>切换tab</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="../demo.css" rel="stylesheet" type="text/css" />  
    <script src="../../scripts/boot.js" type="text/javascript"></script>   
    <style type="text/css"></style>
</head>
<body οnlοad="displaystudentOneTab()">//页面加载完自动执行displaystudentOneTab方法,默认显示第一个tab
<form id="studentForm" name="studentForm" method="post" style="margin:0 -10px">
<table  style="width:100%;margin-top:20px;" cellspacing="1" cellpadding="1" border="0" align="center">
  <tr>
<td>
  <table id="tabTable">
<tr>
  <td id="studentOneTab" οnclick="displaystudentOneTab()">
第一个tab
  </td>
  <td id="studentTwoTab" οnclick="displaystudentTwoTab();">
第二个tab
  </td>
  <td id="studentThreeTab" οnclick="displaystudentThreeTab()">
第三个tab
  </td>
  <td id="studentTourTab" οnclick="displaystudentTourTab()">
第四个tab
  </td>
</tr>
  </table>
</td>
  </tr>
</table>
<div id="studentOneDiv" style="width:100%;margin: 0 auto;display:none"><table border="1" style="width:50%;"  id="class_one">
  <tr>
    <td>姓名</td>
 <td><input name="editName" id="editName" value="小明"/></td>
  </tr>   
  <tr>
    <td>性别</td>
    <td><input name="editGender" id="editGender" value="男" /></td>
  </tr>
  <tr>
<td >年龄</td>
<td><input name="editAge" id="editAge" value="21" /></td>
  </tr>
  <tr>
<td >学号</td>
<td><input name="editNumber" id="editNumber" value="Q100" /></td>
  </tr>
  <tr>
<td>
  <span>  
<a href="#" id="addStudent" οnclick="add_Student(this);return false;">添加</a>
  </span>
</td>
  </tr>
</table></div>
<div id="studentTwoDiv" style="width:100%;margin: 0 auto;display:none"><table border="1" style="width:50%;"  id="class_two">
  <tr>
    <td>姓名</td>
 <td><input name="editName" id="editName" value="小张"/></td>
  </tr>   
  <tr>
    <td>性别</td>
    <td><input name="editGender" id="editGender" value="男" /></td>
  </tr>
  <tr>
<td >年龄</td>
<td><input name="editAge" id="editAge" value="217" /></td>
  </tr>
  <tr>
<td >学号</td>
<td><input name="editNumber" id="editNumber" value="Q140" /></td>
  </tr>
  <tr>
<td>
  <span>  
<a href="#" id="addStudent" οnclick="add_Student(this);return false;">添加</a>
  </span>
</td>
  </tr>
</table></div>
<div id="studentThreeDiv" style="width:100%;margin: 0 auto;display:none"><table border="1" style="width:50%;"  id="class_three">
  <tr>
    <td>姓名</td>
 <td><input name="editName" id="editName" value="小芳"/></td>
  </tr>   
  <tr>
    <td>性别</td>
    <td><input name="editGender" id="editGender" value="女" /></td>
  </tr>
  <tr>
<td >年龄</td>
<td><input name="editAge" id="editAge" value="23" /></td>
  </tr>
  <tr>
<td >学号</td>
<td><input name="editNumber" id="editNumber" value="Q100" /></td>
  </tr>
  <tr>
<td>
  <span>  
<a href="#" id="addStudent" οnclick="add_Student(this);return false;">添加</a>
  </span>
</td>
  </tr>
</table></div>
<div id="studentTourDiv" style="width:100%;margin: 0 auto;display:none"><table border="1" style="width:50%;"  id="class_one">
  <tr>
    <td>姓名</td>
 <td><input name="editName" id="editName" value="小辉"/></td>
  </tr>   
  <tr>
    <td>性别</td>
    <td><input name="editGender" id="editGender" value="男" /></td>
  </tr>
  <tr>
<td >年龄</td>
<td><input name="editAge" id="editAge" value="21" /></td>
  </tr>
  <tr>
<td >学号</td>
<td><input name="editNumber" id="editNumber" value="Q100" /></td>
  </tr>
  <tr>
<td>
  <span>  
<a href="#" id="addStudent" οnclick="add_Student(this);return false;">添加</a>
  </span>
</td>
  </tr>
</table></div>

</form>

JS部分:

<script type="text/javascript">
function displaystudentTwoTab() {
$("#studentTwoDiv").show();//选中的显示,其余的隐藏
$("#studentTwoTab").css({"background-color":"#50ffba"});//加以颜色区分
$("#studentThreeTab").css({"background-color":"#F5F5F5"});
$("#studentTourTab").css({"background-color":"#F5F5F5"});
$("#studentOneTab").css({"background-color":"#F5F5F5"});
$("#studentThreeDiv").hide();
$("#studentTourDiv").hide();
$("#studentOneDiv").hide();
}
function displaystudentThreeTab() {
$("#studentTwoDiv").hide();
$("#studentThreeDiv").show();
$("#studentThreeTab").css({"background-color":"#50ffba"});
$("#studentTwoTab").css({"background-color":"#F5F5F5"});
$("#studentTourTab").css({"background-color":"#F5F5F5"});
$("#studentOneTab").css({"background-color":"#F5F5F5"});
$("#studentTourDiv").hide();
$("#studentOneDiv").hide();
}
function displaystudentTourTab() {
$("#studentTwoDiv").hide();
$("#studentThreeDiv").hide();
$("#studentTourDiv").show();
$("#studentTourTab").css({"background-color":"#50ffba"});
$("#studentThreeTab").css({"background-color":"#F5F5F5"});
$("#studentTwoTab").css({"background-color":"#F5F5F5"});
$("#studentOneTab").css({"background-color":"#F5F5F5"});
$("#studentOneDiv").hide();
}
function displaystudentOneTab() {
$("#studentOneDiv").show();
$("#studentOneTab").css({"background-color":"#50ffba"});
$("#studentTourTab").css({"background-color":"#F5F5F5"});
$("#studentThreeTab").css({"background-color":"#F5F5F5"});
$("#studentTwoTab").css({"background-color":"#F5F5F5"});
$("#studentTwoDiv").hide();
$("#studentThreeDiv").hide();
$("#studentTourDiv").hide();
}
</script>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值