zoukankan      html  css  js  c++  java
  • 函数必须绑定事件才可以

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     6 <title>练习</title>
     7 <style type="text/css">
     8     div{width: 300px;height: 300px;border:1px solid #ccc;}
     9 </style>
    10 <script type="text/javascript">
    11 window.onload=function (){
    12     document.getElementById('btn').=function (){
    13         document.getElementsByTagName('div')[0].style.background='red';
    14     }
    15 }
    16 </script>
    17 </head>
    18 <body>
    19 <input type="button" value="变红" id="btn"/>
    20 <div></div>
    21 </body>
    22 </html>

    因为button后面没有对要写的函数绑定事件

    解决办法:

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     6 <title>练习</title>
     7 <style type="text/css">
     8     div{width: 300px;height: 300px;border:1px solid #ccc;}
     9 </style>
    10 <script type="text/javascript">
    11 window.onload=function (){
    12     document.getElementById('btn').onclick=function (){
    13         document.getElementsByTagName('div')[0].style.background='red';
    14     }
    15 }
    16 </script>
    17 </head>
    18 <body>
    19 <input type="button" value="变红" id="btn"/>
    20 <div></div>
    21 </body>
    22 </html>
    衣带渐宽终不悔,为伊消得人憔悴,憔悴半天也没用,还是努力起来人富贵
  • 相关阅读:
    zookeeper集群搭建2.7
    hadoop集群环境搭建
    Kettle(6.0) 参数方式连接数据库
    kettle数据同步的5中方案
    kettle 合并记录步骤中的 关键字段和 比较字段的说明
    KETTLE常见问题和优化
    Hbase与Oracle的比较
    EHCache
    hdu2014 青年歌手大奖赛_评委会打分【C++】
    hdu2013 蟠桃记【C++】
  • 原文地址:https://www.cnblogs.com/zhangjingyun/p/4663723.html
Copyright © 2011-2022 走看看