前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JQuery排他思想-按钮点击变色事件按钮制作

JQuery排他思想-按钮点击变色事件按钮制作

作者头像
梦溪
发布2021-08-23 10:44:01
10.1K0
发布2021-08-23 10:44:01
举报
文章被收录于专栏:梦溪博客梦溪博客

点击按钮的时候,被点击按钮颜色变化,其他按钮要保持不变。

代码语言:javascript
复制
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]>      <html class="no-js"> <!--<![endif]-->
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="">
        <style>
            div {
                width: 370px;
                margin: 100px auto;
              
            }
        </style>
        <script src="jquery.min.js"></script>
    </head>
    <body> 
        <div >   
            <button>我是一号</button>
            <button>我是二号</button>
            <button>我是三号</button>
            <button>我是四号</button>
            <button>我是五号</button>
        </div>  
        <script>
            $(function() {
                $("button").click(function() {
                    $(this).css("background", "gray");
                    $(this).siblings("button").css("background", "");
                }); 
            })
             
        </script>
    </body>
</html>

版权属于:Cyril 本文链接:https://www.cyrilstudio.top/archives/572/ 转载时须注明出处及本声明

点击按钮的时候,被点击按钮颜色变化,其他按钮要保持不变。

代码语言:javascript
复制
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]>      <html class="no-js"> <!--<![endif]-->
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="">
        <style>
            div {
                width: 370px;
                margin: 100px auto;
              
            }
        </style>
        <script src="jquery.min.js"></script>
    </head>
    <body> 
        <div >   
            <button>我是一号</button>
            <button>我是二号</button>
            <button>我是三号</button>
            <button>我是四号</button>
            <button>我是五号</button>
        </div>  
        <script>
            $(function() {
                $("button").click(function() {
                    $(this).css("background", "gray");
                    $(this).siblings("button").css("background", "");
                }); 
            })
             
        </script>
    </body>
</html>

版权属于:Cyril 本文链接:https://www.cyrilstudio.top/archives/572/ 转载时须注明出处及本声明 点击按钮的时候,被点击按钮颜色变化,其他按钮要保持不变。

代码语言:javascript
复制
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]>      <html class="no-js"> <!--<![endif]-->
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="">
        <style>
            div {
                width: 370px;
                margin: 100px auto;
              
            }
        </style>
        <script src="jquery.min.js"></script>
    </head>
    <body> 
        <div >   
            <button>我是一号</button>
            <button>我是二号</button>
            <button>我是三号</button>
            <button>我是四号</button>
            <button>我是五号</button>
        </div>  
        <script>
            $(function() {
                $("button").click(function() {
                    $(this).css("background", "gray");
                    $(this).siblings("button").css("background", "");
                }); 
            })
             
        </script>
    </body>
</html>

版权属于:Cyril 本文链接:https://www.cyrilstudio.top/archives/572/ 转载时须注明出处及本声明

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021 年 08 月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档