JavaScript review exercise

first question:

1, equal to the number of elements to add click event

1) "=" The above elements added onclick attribute = "GetSum ()" in
2) access "=" element, the element .onclick = function jia js file () {

}

备注:onmouseover、onmouseout、onmousedown、onmouseup、onkeydown、onkeypress、onkeyup

2, defined functions, to achieve the effect of post-click

1) obtaining a first value and a second text box

var firstNum= document.getElementById("first").value;
var secondNum= document.getElementById("second").value;

Note: document.getElementsByName ( "zhangsan")
document.getElementsByTagName ( "tag name")
value, innerText, the difference between three innerHTML attribute <li> <a> League </a> </ li>
system function: parseInt, isNaN parseFloat

2) are summed and assigned to the third text box

var sum=firstNum+secondNum
document.getElementById("thrid").value=sum

The second question:

1) How to enable button

. document.getElementById ( "btnShow") Disabled = false;

2) how to make digital buttons decrement

var n = 5;


Time function () {

. document.getElementById ( "btnShow") value = "read the agreement carefully (" NUM + + ")";
num--;
}

var mySetInterval = setInterval ( "time ()", 1000); - every second function execution time ()

3) how to stop decreasing numbers equal to 0 and enabled Button

function Time () {
  // decrement when num is greater than 0, and a digital output, otherwise, the button text to "agree" and enable the button, 
  IF (num> 0 ) { 
    document.getElementById ( "btnShow"). value = "Please read the agreement (" + NUM + ")" ; 
    NUM - ; 
  } the else {
    // the button text to "agree" 
    // enable button 
    // clear the timer function, or an infinite loop resulting in post-page Caton 
  } 

}

Note: setInterval, clearInterval, setTimeout, clearTimeOut timing of four functions

Third question:

Thinking: How to achieve a mouse moved in and out, how to determine whether the current li into
how the mouse to click and delete the current element, added to in the second ul

1) to the first li ul was added under the onmouseover (mouse move), onmouseout (mouse out) properties

例如:<li onmouseover="addBgColor(this)" onmouseout="removeBgColor(this)">火箭</li>

Note: Each function of this representative of the current element

2) to specify the function onmouseover event, realize the background color is red

function addBgColor(obj){
obj.style.backgroundColor="red";
}

3) to the onmouseout event specified function to achieve red background removal function (the background color to white)

function removeBgColor(obj){
obj.style.backgroundColor="white";
}

4) next to the first li ul onclick attribute added

例如:<li onmouseover="addBgColor(this)" onmouseout="removeBgColor(this)" onclick="moveLi(obj)">火箭</li>


5) to the onclick event specified function, realize delete the current element, added to the current element in the second ul (this parameter represents the current element)

function moveLi (obj) {
 // delete current element 
document.getElementById ( "firstUL" ) .removeChild (obj);
 // appends the current element to a second obj ul is 
document.getElementById ( "secondUL" ) .appendChild (obj ) 
}

Guess you like

Origin www.cnblogs.com/autism-dong/p/12106658.html