zoukankan      html  css  js  c++  java
  • 代码-JS之点击更换背景

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
    <!--编写HTML-->
    <table border="1" cellspacing="0" cellpadding="2" rules="all" width="200">
        <tr>
            <td style="background-color: blue;">&nbsp;</td>
            <td style="background-color: brown;">&nbsp;</td>
        </tr>
        <tr>
            <td style="background-color: crimson;">&nbsp;</td>
            <td style="background-color: orange">&nbsp;</td>
        </tr>
    </table>
    <!--编写JavaScript-->
    <script>
        //找到页面中所有的td
        var tds = document.getElementsByTagName('td');
        for(var i=0; i<tds.length; i++){
            //绑定单击事件
            tds[i].onclick = function(){
                //更换背景
                document.body.style.backgroundColor = this.style.backgroundColor;
            };
        }
    </script>
    
    </body>
    </html>
    
    Copyright [2018] by [羊驼可以吃吗] form [https://www.cnblogs.com/phpisfirst/]
  • 相关阅读:
    (五)Redis在项目中应用
    股票收益最大问题
    (四)redigo
    (三)go-sql-driver
    为什么TCP要3次握手?4次挥手?
    分支预测
    事务隔离级别说明
    剑指offer解题思路锦集11-20题
    C++中的二义性问题
    memcached Vs redis
  • 原文地址:https://www.cnblogs.com/phpisfirst/p/9819142.html
Copyright © 2011-2022 走看看