多种方法实现按钮开关

<!doctype html>
<html>
<head>
<title>your name</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
    button{
        width:100px;
        height:100px;
    }
    button.change{
        background:red;
    }
</style>
</head>
<body>
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<div>我是内容1</div>
<div>我是内容2</div>
<div>我是内容3</div>
<div>我是内容4</div>
<script>
    var obut=document.getElementsByTagName("button");
    var odiv=document.getElementsByTagName("div");
    obut[0].onclick=function(){
        obut[0].className="change";
        obut[1].className="";
        obut[2].className="";
        obut[3].className="";
        odiv[0].style.display="";
        odiv[1].style.display="none";
        odiv[2].style.display="none";
        odiv[3].style.display="none";

    }
    obut[1].onclick=function(){
        obut[0].className="";
        obut[1].className="change";
        obut[2].className="";
        obut[3].className="";
        odiv[0].style.display="none";
        odiv[1].style.display="";
        odiv[2].style.display="none";
        odiv[3].style.display="none";

    }
    obut[2].onclick=function(){
        obut[0].className="";
        obut[1].className="";
        obut[2].className="change";
        obut[3].className="";
        odiv[0].style.display="none";
        odiv[1].style.display="none";
        odiv[2].style.display="";
        odiv[3].style.display="none";

    }
    obut[3].onclick=function(){
        obut[0].className="";
        obut[1].className="";
        obut[2].className="";
        obut[3].className="change";
        odiv[0].style.display="none";
        odiv[1].style.display="none";
        odiv[2].style.display="none";
        odiv[3].style.display="";
    }
</script>

</body>
</html>
<script type="text/javascript" src="script.js"></script>
<!doctype html>
<html>
<head>
<title>your name</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
    button{
        width:100px;
        height:100px;
    }
    button.change{
        background:red;
    }
</style>
</head>
<body>
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<div>我是内容1</div>
<div>我是内容2</div>
<div>我是内容3</div>
<div>我是内容4</div>
<script>

    var obut=document.getElementsByTagName("button");
    var odiv=document.getElementsByTagName("div");

    for(let i=0;i<4;i++){
        obut[i].onclick=function(evt){
            for(let j=0;j<4;j++){
                if(j==i){
                    //alert("i:"+i+"j:"+j+"hello");
                    obut[j].className="change";
                    odiv[j].style.display="";
                }else{
                    obut[j].className="";
                    odiv[j].style.display="none";
                    //alert("i:"+i+"j:"+j+"world");
                }
            }
        }

    }

</script>

</body>
</html>
<script type="text/javascript" src="script.js"></script>
时间: 2024-08-11 12:35:51

多种方法实现按钮开关的相关文章

C语言轻松高效学习方法之:多种方法实现

多种方法实现同一个功能,可以调动你学的所有知识去做,有助于你学的融会贯通. 下面举例来看: 实现功能:求一个整数的位数: 实现语言:C语言: 开发环境:Visual Studio 2017 如:3215是4位数 实现原理: 3215/10 = 321 ----1位数 321/10 = 32 ----又是1位数 32/10 = 3 ----又是1位数 3/10 = 0 ----又是1位数 共4位数,且终止计算条件是/10结果为0的时候: 根据这个原理,先写一个最笨的原始方法: 效果: 这种实现方案

教你用多种方法将pdf文件转换成jpg

我们在工作中经常会遇到pdf与word.excel.jpg等格式文件的转换,可是怎样才能把两种文件转换的完整有效呢?下面小编就pdf与jpg这两种格式来讲一下它们是如何转换的! pdf文件转换成jpg都有哪些方法? pdf文件转换成jpg有很多种方法,这里我们介绍最简单的三种,第一种是使用Adobe acrobat另存为jpg图片:另一种是在线将pdf转换成jpg; 还有一种方法可以使用第三方软件迅捷pdf转换器将pdf转换成jpg. 一.使用Adobe acrobat另存为jpg图片 用Ado

在域中获取域管理员权限的多种方法及一些缓解措施

翻译:hac425 前言 现在攻击者有很多方法可以用来获取域管理员权限.这篇文章的目的是介绍一些当前较受欢迎的方式.这里所介绍的技术的基本点是攻击者已经拿到了一台域中的服务器,并已获得域用户凭据. 对大多数企业来说有一个不幸的现实:对于一个攻击者来说,从域用户权限提升到域管理员权限往往不需要太长的时间.为什么会这样呢?本文会介绍其中使用的一些技巧. 现在针对一个企业,组织的攻击越来越频繁通过一些钓鱼手法来开始.比如通过发送大量的钓鱼邮件给目标的成员来在目标网络的机器上执行代码.一旦攻击者能够在企

js返回上一页并刷新的多种方法

js返回上一页并刷新的几种方法.参考链接:http://www.jbxue.com/article/11230.html <a href="javascript:history.go(-1)">返回上一页</a><a href="javascript:location.reload()">刷新当前页面</a><a href="javascript:" onclick="history

VC开发多语言界面 多种方法(很简单) 有源码

(需源码先留邮箱)先上图 1.通过遍历 得到所有控件ID号与TEXT,得到一个中文语言配置文件 void CVV_485Dlg::getCaptionForWindow() //做程序时用,其它时间不用 { //枚举对话框中所有组件 CWnd *pCtrl = GetWindow(GW_CHILD); while(pCtrl!=NULL) { UINT ctrlID = pCtrl->GetDlgCtrlID(); // setControlCaption(pCtrl,ctrlID); CStr

shell编程基础一(多种方法求值1+2+..+100)

#SHELL编程基础一(多种方法求值1+2+..+100)##为什么要学好shell shell脚本语言是实现linux系统管理及自动化运维所必备的重要工具,linux系统的底层及基础应用软件的核心大都涉及shell脚本的内容. 每一个合格的linux系统管理员或运维工程师,都需要能够熟练地编写shell脚本语言,并能够阅读系统及各类软件附带的shell脚本内容. 只有这样才能提升运维人员的工作效率,适应日益复杂的工作环境,减少不必要的工作,从而为个人的职场发展奠定较好的基础.# 本文的宗旨是熟

文件下载的多种方法

if (Request["name"] != null)        {            try            {                string FileName = MyCrypt.Decrypt(Request["name"]);                //string FilePath = Server.MapPath(string.Format("UploadFile/{0}", FileName))

poj_1018_多种方法求解

Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22445   Accepted: 7977 Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices.

js实现页面跳转重定向多种方法

分享下js实现页面跳转重定向的几种方式. 第一种: <script language="javascript"type="text/javascript"> window.location.href="http://www.jbxue.com"; </script> 第二种: <script language="javascript"> alert("返回"); wind