This article describes the method of dynamically modifying Li node values in JavaScript. Share it for your reference. The specific implementation method is as follows:
The code copy is as follows:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Modify the value of Li</title>
<script type="text/javascript">
function gel(id) {
return document.getElementById(id);
}
//Global input input control
var inpt = document.createElement("input");
inpt.setAttribute("type", "text");
inpt.onblur = function() {
//alert("tet");
this.parentElement.innerHTML = inpt.value;
};
window.onload = function() {
var lis = gel("ulList").childNodes;
for (var i = 0; i < lis.length; i++) {
if (lis[i].nodeType == 1) {
lis[i].ondblclick = function () {
//Delete text
inpt.value = this.innerHTML;
this.removeChild(this.firstChild);
this.appendChild(inpt);
//Get focus
inpt.focus();
//When the inpt control loses focus, you must also bind an event and return the text value in inpt to the current li
//Writing inpt.onblur
};
}
}
};
</script>
</head>
<body>
<ul id="ulList">
<li>Beijing</li>
<li>Shanxi</li>
<li>Shanghai</li>
<li>Tianjin</li>
<li>Henan</li>
</ul>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.