这里有新鲜出炉的 Javascript 教程,程序狗速度看过来!
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
本文主要介绍了 js 实现简单的选项卡效果的示例代码,具有很好的参考价值,下面跟着小编一起来看下吧
效果如下:
代码如下:
- <!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" />
- <title>
- 无标题文档
- </title>
- <style>
- div{width:200px;height:100px;border:1px red solid;display:none};
- </style>
- <script>
- window.onload = function() {
- var oDiv = document.getElementsByTagName("div") var oIput = document.getElementsByTagName("input") oDiv[0].style.display = "block";
- var ten = oIput[0]
- for (i = 0; i < oIput.length; i++) {
- oIput[i].indent = i
- //通过自定义属性获得下标值
- oIput[i].onclick = function() {
- ten.style.background = ''oDiv[ten.indent].style.display = "none"
- //点击时把上一个隐藏
- this.style.background = "yellow"oDiv[this.indent].style.display = "block"ten = this
- }
- }
- }
- </script>
- </head>
- <body>
- <input type="button" value="按钮一" style="background:yellow" />
- <input type="button" value="按钮二" />
- <input type="button" value="按钮三" />
- <div>
- 1
- </div>
- <div>
- 2
- </div>
- <div>
- 3
- </div>
- </body>
- </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持 phperz!
(adsbygoogle = window.adsbygoogle || []).push({});
来源: http://www.phperz.com/article/17/0630/327328.html