zoukankan      html  css  js  c++  java
  • jQuery——开关灯

    js对象与jquery对象的相互转化:

    1、$(js对象)

    2、$(selector).get(索引)、$(selector)[索引]

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            div {
                width: 700px;
                height: 600px;
                margin: 50px auto;
                background-color: blue;
            }
        </style>
        <script src="jquery-1.11.1.js"></script>
        <script>
            // $(document).ready(function () {
            //     $("button:eq(0)").click(function () {
            //         $("body").css("backgroundColor", "");
            //     });
            //     $("button:eq(1)").click(function () {
            //         $("body").css("backgroundColor", "black");
            //     });
            // });
    
            $(function () {
                var btnArr = document.getElementsByTagName("button");
                $(btnArr[0]).click(function () {
                    $("body").get(0).style.backgroundColor = "";
    
                });
                $(btnArr[1]).click(function () {
                    $("body")[0].style.backgroundColor = "black";
    
                });
            });
        </script>
    </head>
    <body>
    <button>开灯</button>
    <button>关灯</button>
    <div></div>
    </body>
    </html>

  • 相关阅读:
    事后诸葛亮
    冲刺总结
    Alpha第十天
    Alpha第八天
    Alpha第九天
    Alpha第六天
    Alpha第七天
    Alpha第五天
    Python之pytesseract模块-实现OCR
    Selenium4 IDE初体验
  • 原文地址:https://www.cnblogs.com/wuqiuxue/p/8031363.html
Copyright © 2011-2022 走看看