• JS中,根据div数值判断弹出窗口


    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style type="text/css">

    div{

    width: 50px;

    height: 50px;

    margin: 20px;

    float: left;

    border: 1px solid orange;

    }

    </style>

    </head>

    <body>

    <div id="div1">1</div>

    <div id="div2">2</div>

    <div id="div3">3</div>

    <div id="div4">4</div>

    <div id="div5">5</div>

    <div id="div6">6</div>

    <div id="div7">7</div>

    <div id="div8">8</div>

    <div id="div9">9</div>

    <div id="div10">10</div>

    </body>

    <script type="text/javascript">

     //需求:偶数弹出窗口

    for (var i=1;i<=10;i++) {

    //挨个获取div

    var div=document.getElementById("div"+i);

    //得到div的内容,并转换成数据类型

    var num=Number(div.innerHTML);

    if(num%2==0){

    //将满足条件的div的点击事件绑定对应的函数体

    div.onclick=function(){

    alert("popo,coming!");

    }

    }

    }

    </script>

    </html>

  • 相关阅读:
    mac lsof使用查看端口
    mac 安装gevent报错
    vim命令学习
    linux批量关闭进程
    坐标点转换
    screen命令记录
    hashlib模块
    PyYAML和configparser模块讲解
    xml处理模块
    json、pickleshelve模块(超级好用~!)讲解
  • 原文地址:https://www.cnblogs.com/niuniudashijie/p/5988528.html
Copyright © 2020-2023  润新知