本文实例为大家分享了js编写简单选项卡的具体代码,供大家参考,具体内容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery选项卡</title>
<style type="text/css">
#p1 p{width: 200px;height: 200px;border: 1px red solid;display: none;}
.active{background:#999;}
</style>
<!-- 原生的JS -->
<script type="text/javascript">
window.onload=function(){
var op=document.getElementById('p1');
var aInput=document.getElementsByTagName('input');
var aCon=op.getElementsByTagName('p');
for (var i = 0; i < aInput.length; i++) {
aInput[i].index=i;
aInput[i].onclick=function(){
for (var i = 0; i < aInput.length; i++) {
aInput[i].className='';
aCon[i].style.display='';
}
this.className='active';
aCon[this.index].style.display='block';
}
}
}
</script>
<!-- jquery写法 -->
<script type="text/javascript" src='../jquery-3.2.1.min.js'></script>
<script type="text/javascript">
$(function(){
$('#p1').find('input').click(function(){
$('#p1').find('input').attr('class','');
$('#p1').find('p').css('display','none');
$(this).attr('class','active');
$('#p1').find('p').eq($(this).index()).css('display','block');
})
})
</script>
</head>
<body>
<p id="p1">
<input class="active" type="button" value="1">
<input type="button" value="2">
<input type="button" value="3">
<p style="display: block;">11111</p>
<p>22222</p>
<p>33333</p>
</p>
</body>
</html>以上就是JS+jQuery编写简单选项卡的示例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号