• JavaScript 学习笔记— —自定义属性


    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript">
    window.onload=function()
    {
        //自定义属性
        var oDiv1=document.getElementById("div1");
        var aBtn=oDiv1.getElementsByTagName("input");
        var arr=['A','B','C','D']
        for(var i=0;i<aBtn.length;i++){
            aBtn[i].num=0;//给input标签增加num="0"属性
            aBtn[i].onclick=function(){
                this.value=arr[this.num];
                this.num++;
                if(this.num==arr.length){
                    this.num=0;
                }
            }
        }
    
        //自定义索引
        var oDiv2=document.getElementById("div2");
        var oBtn=oDiv2.getElementsByTagName("input");
        var arrCity=['北京','上海','合肥']
        for(var i=0;i<oBtn.length;i++){
            oBtn[i].index=i;//自定义索引
            oBtn[i].onclick=function(){
                this.value=arrCity[this.index];
            }
        }
    }
    </script>
    </head>
    <body>
    <div id="div1">
        <input type="button" value="0" />
        <input type="button" value="0" />
        <input type="button" value="0" />
    </div>
    
    <div id="div2">
        <input type="button" value="0" />
        <input type="button" value="0" />
        <input type="button" value="0" />
    </div>
    
    </body>
    </html>
  • 相关阅读:
    Android_程序未处理异常的捕获与处理
    instanceof关键字
    乐优商城项目爬坑
    [LeetCode]Isomorphic Strings
    [LeetCode]Contains Duplicate II
    [LeetCode]Valid Sudoku
    [LeetCode]Valid Anagram
    [LeetCode]Contains Duplicate
    [LeetCode]Single Number
    [LeetCode]Valid Number
  • 原文地址:https://www.cnblogs.com/eaysun/p/4387137.html
Copyright © 2020-2023  润新知