< ;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> The use of setInterval and setTimeout in js < ;script type="text/javascript"> var time = 10; var id = 0; function gel(id) { return document.getElementById(id); }
function dectime() { if (time > 0) { time--; gel("timespan").innerHTML = time; } else { //Clear the hour hand clearInterval(id); } }
window.onload = function() { id = setInterval(dectime, 1000); };
js dynamically obtains, creates and deletes nodes < script type="text/javascript"> function gel(id) { return document.getElementById(id); }
window.onload = function () { gel("btnProAdd" ).onclick = function () { //Add child nodes under proList var linew = document.createElement("li"); linew.innerHTML = prompt("Enter the province to be added "); gel("proList").appendChild(linew); //Rebind all click delete events DelLiOnClick(); };
/ /Double-click the li child node to delete it
function DelLiOnClick() { //1. First get all the child nodes var liNodes = gel("proList").childNodes;
for (var i = 0; i < liNodes.length; i ) { liNodes[i].onclick = function () { //alert(liNodes[i]).innerHTML;/ /Because onclick is bound to an anonymous function, so i will always be 7 here //The following is the correct way to delete, use this. Because the onclick event is always triggered by the li you selected this. parentNode.removeChild(this); }; } }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn