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

2021-08-23 10:44:01 浏览数 (1)

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

代码语言: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/ 转载时须注明出处及本声明

0 人点赞