JS problems encountered in doing projects

name和value:

E.g:

    
<input type="text" name="txt"/>

name used to define the value of this variable name input received, input inputted in the above "hello", then there is txt = "hello"; operation value for dom

When changing a div attribute values ​​pass operation with js, div actually can name, for example:

<div class="div_1" name="0" style="background-color:red" onClick="change_color(this)"></div>
1
    
<div class="div_1" name="1" style="background-color:black" onClick="change_color(this)"></div>
1
2
3
4
5
6
7
    
// define a div class name the same array index var index = null <br>; <br> // define the variable is empty, find div by class name 
var div_1_change = null ; <br> // invoked when a mouse click function 
function change_color (Flag) <br> { // index value is the name div value 
    index = flag.getAttribute ( " name " ); <br> // find div 
   div_1_change = document.getElementsByClassName ( " div_1 " ); <br> // change the background color 
   div_1_change [index] .style.backgroundColor = " Blue " ;
}
<input type="button" value="btn"/>

value is the value of the input, and it is displayed out of something, the text on the button btn;

name和value:

E.g:

    
<input type="text" name="txt"/>

name used to define the value of this variable name input received, input inputted in the above "hello", then there is txt = "hello"; operation value for dom

When changing a div attribute values ​​pass operation with js, div actually can name, for example:

<div class="div_1" name="0" style="background-color:red" onClick="change_color(this)"></div>
1
    
<div class="div_1" name="1" style="background-color:black" onClick="change_color(this)"></div>
1
2
3
4
5
6
7
    
// define a div class name the same array index var index = null <br>; <br> // define the variable is empty, find div by class name 
var div_1_change = null ; <br> // invoked when a mouse click function 
function change_color (Flag) <br> { // index value is the name div value 
    index = flag.getAttribute ( " name " ); <br> // find div 
   div_1_change = document.getElementsByClassName ( " div_1 " ); <br> // change the background color 
   div_1_change [index] .style.backgroundColor = " Blue " ;
}
<input type="button" value="btn"/>

value is the value of the input, and it is displayed out of something, the text on the button btn;

Guess you like

Origin www.cnblogs.com/LQK157/p/11027747.html