Click on each Li node to pop its text value
1, get all the LI nodes
var liNodes=document.GetElementsByTagName("li");
2, using a For loop to traverse, get every Li node
for (Var i=0;i<linodes.length;i++) {
alert (i);
}
3, add the onclick response function for each Li node
liNodes[i].onclick=function(){ }
4, gets the text value of the current node in the response function
This is the node that is responding to the event
alert(this.firstChild.nodeValue);
Click on each Li node, if the Li node text value does not start, plus;
var linodes=document.getelementsbytagname ("Li");//Get for
(var i=0;i<linodes.length;i++) {//Traverse
linodes[i ].onclick=function () {//Response to
var Val=this.firstchild.nodevalue;
var reg=/^\^{2}/g;//global Regular
if (Reg.test (val)) {//Judge
Val=val.replace (Reg, "");
}
else{
val= "^^" +val;
}
Firstchild.nodevalue=val;
}
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!