Use JavaScript to write an add-minus button on the page to achieve the cumulative number of numbers.
The abbreviated HTML is probably the case. If you can read it, don't mind the details.
1 <inputtype= "button"value="+"onclick= "Jia (this)" />2 <labelclass= "num">0</label>3 <inputtype= "button"value="-"onclick= "Jian (this)" />
It looks like this.
The JavaScript code is as follows
1<script type= "Text/javascript" >2 functionJia (a)3 {4 varNextNode = a.nextelementsibling;//Get Next node5 6 alert (nextnode.innerhtml);7 varA =parseint (nextnode.innerhtml)8A + = 1;9nextnode.innerhtml =A;Ten One A } - functionJian (a) { - varPreviousnode =a.previouselementsibling; the varA =parseint (previousnode.innerhtml) -A-= 1; -A = a > 0? a:0; -previousnode.innerhtml =A; + } -</script>
Explain:
function Jian (a) and
function Jia (a) is the object of the current click. Add this to the OnClick event method;
-Nextelementsibling Gets the next node of the current node (obtains the next sibling node)
-Previouselementsibling Gets the previous node of the current node
Note: IE skips the space between nodes (for example: newline characters), and Mozilla does not--ff such a layout element such as a space wrap is treated as a node read, so the next node element can be read in IE with nextsibling, This is what you need to write in FF: nextelementsibling.
The above explanation means using nextelementsibling and previouselementsibling to get the next sibling node and the previous sibling node, you can remove the newline, the space above and so on, directly find our tag element. But the following two
NextSibling
PreviousSibling is also the next sibling node and the previous sibling node, just easy to use in IE
--------------------keyword Explanation
parseint conversion function.
A = a > 0? a:0;----three-dimensional expression.
JavaScript gets the next node of the DOM book.