1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 7 8 </Head>9 <Body>Ten <inputtype= "button"name=""class= "BTN"value= "Test 1" /> One <inputtype= "button"name=""class= "BTN"value= "Test 2" /> A <inputtype= "button"name=""class= "BTN"value= "Test 3" /> - - </Body> the - <Scripttype= "Text/javascript"> - //Custom Properties - varButton=document.getElementById ("btn"); + //create attributes that don't mess with - Button.guoxiaomin= "1"; + Console.log (button.guoxiaomin); A at varBtns=Document.getelementsbyclassname ("btn"); - varcorlors= ["Red","Green","Yellow"]; - for (varI= 0; I< 3; I++) { - //record the value of I using a custom attribute - Btns[i].index=i; - Console.log (Btns[i].index); in Btns[i].onclick= function(){ - if( This. Index== 0){ to Document.body.style.background= "Red"; + }Else if( This. Index== 1){ - Document.body.style.background= "Green"; the }Else{ * Document.body.style.background= "Yellow"; $ }Panax Notoginseng Document.body.style.background=corlors[ This. index]; - the } + } A the + for (varI= 0; I< 3; I++) { - $ }console.log (i); $ //First assignment: i = 0; then I < 3?; if Console.log (i) is performed on true side, the last i++; - - the </Script> - Wuyi the </HTML>
JS Custom Properties