console
window.onload = function(){
var oDiv1=document.getElementById("Div1");
console.log("The node type of oDiv1 is"+oDiv1.nodeType);
var oAttributeNode =oDiv1.getAttributeNode("id");
console.log("The node type of oAttributeNode is"+oAttributeNode.nodeType);
var oTextNode=oDiv1.childNodes[0];
console.log("The node type of oTextNode is "+oTextNode.nodeType);
var oDivs = document.getElementsByTagName("div");
console.log("The length of oDivs is "+oDivs.length);
if(oDiv1 == oDivs[0]){
console.log("We are the same node." );
}
var oUls = document.getElementsByTagName("ul");
var oLisInUll = oUls[0].getElementsByTagName("li");
var oLisInDoc=document.getElementsByTagName("li");
console.log("The length of oLisInUll is "+oLisInUll.length);
console.log("The length of oLisInDoc is "+oLisInDoc.length);
var oLists = document.getElementsByClassName("list")
console.log("The length of oLists is "+oLists.length);
var oRadios = oDivs[1].getElementsByClassName("radio");
console.log("The length of oRadios is "+oRadios.length);
var oRadios3 = oDivs[2].getElementsByClassName("radio");
console.log("The length of oRadios3 is "+oRadios3.length);
var oInputFemale = document.querySelector("input:checked");
console.log("line 54: "+oInputFemale.value);
var oInputs = document.querySelectorAll("input");
console.log("line 57: "+oInputs.length);
oInputs[1].checked = true;
oInputs[3].checked = true;
var oClassInputs = document.querySelectorAll(".radio");
oClassInputs[0].checked = true;
var oLi11= document.querySelector("#li11");
oLi11.style.color = "red";
var oList2Lis = document.querySelectorAll("#List2 li");
oList2Lis[0].style.color = "blue";
oList2Lis[1].style.color = "green";
oList2Lis[2].style.color = "orange";
var oNamedRadios = document.getElementsByName("gender");
console.log("line 80: "+ oNamedRadios[0].value);
oNamedRadios[1].checked = true;
var oFruitS = document.getElementsByName("furit");
console.log("line 81: "+oFruitS[0].value);
oFruitS[0].checked = false;
console.log(document.title);
console.log(document.body.tagName);
document.title = "hello DOM";
var oDynamicButton = document.createElement("button");
var oTextNode = document.createTextNode("提交");
oDynamicButton.appendChild(oTextNode);
document.body.insertBefore(oDynamicButton,oUls[0]);
oDynamicButton.onclick = function(){
var oDiv1 = document.getElementById("Div1");
var oPHi = document.createElement("p");
var oPText = document.createTextNode("Hi");
oPHi.appendChild(oPText);
oDiv1.replaceChild(oPHi,oDiv1.childNodes[1]);
}
console.log("Line 114: The id of oDiv1: "+oDiv1.id);
console.log("Line 116: The id of oDiv1: "+oDiv1.getAttribut("id"));
console.log("Line 115: The id of oDiv1: "+oDiv1.data);
console.log("Line 116: The id of oDiv1: "+oDiv1.getAttribut("data"));
console.log("Line 117: The id of oDiv1: "+oDiv1.className);
var oInput = document.getElementById(insertInput);
oInput.setAttribute("value","Enter");
oInput.removeAttribute("value");
if(oInput.hasAttribute("value")){
console.log("value is the attribute of oInput");
}
}
function insertChild() {
var oInput = document.getElementById("insertInput");
var oInputText = oInput.value;
console.log(oInputText);
var oUl = document.getElementById("List1");
var oLis = oUl.getElementsByTagName("li");
var oCreatedLi = document.createElement("li");
var oLiText = document.createTextNode(oInputText);
oCreatedLi.appendChild(oLiText);
oUl.insertBefore(oCreatedLi, oLis[0]);
}
function insertToList(){
var oInput = document.getElementById("insertInput");
var oInputText = oInput.value;
console.log(oInputText);
var oUI = document.getElementById("List1");
var oLis = oUI.getElementsByTagName("li");
var oCreatedLi = oLis[0].cloneNode(false);
oCreatedLi.textContent = oInputText;
oUl.insertBefore(oCreatedLi,oLis[0]);
}
function removeTop(){
var oUl = document.getElementById("List1");
var oLis = oUl.getElementsByTagName("li");
oUl.removeChild(oLis[0]);
}
function appendTolist(){
var oInput = document.getElementById("appendInput");
var strValue = oInput.value;
var oList2 = document.getElementById("List2");
var oLis = oList2.getElementsByTagName("li");
var oCreatedLi = oLis[1].cloneNode(true);
oCreatedLi.textContent = strValue;
oList2.appendChild(oCreatedLi);
}
function removeBottom(){
var oList1 = document.getElementById("List2");
var oLis = document.getElementsByName("li");
oList1.removeChild(oLis[oLis.length - 1]);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="Div1" data="userDefined" class="div1">
<p id="Paragraph">Hello</p>
World
</div>
<ul id="List1" class="list">
<li id = "Li11"> Html </li>
<li> Javascript </li>
<li> CSS </li>
<li> Webpack </li>
</ul>
<input id="insertInput" type="text"></input>
<button onclick="insertChild">插入列表元素顶部</button>
<ul id="List2" class="list">
<li> Vue </li>
<li> React </li>
<li> Angular </li>
</ul>
<input id="appendInput" type="text"></input>
<button onclick="appendChild()">添加到列表元素的尾部</button>
<div>
你的性别是:
<input class="radio" type="radio" name="gender" checked="true" value="女">女</input>
<input class="radio" type="radio" name="gender" value="男">男</input>
</div>
<div>
你喜欢那些水果:
<input type="checkbox" name="fruit" checked="true" value="苹果">苹果</input>
<input type="checkbox" name="fruit" value="梨">梨</input>
</div>
<div id="DynamicDiv1"></div>
<div id="DynamicDiv2"></div>
</body>
</html>
#Div1{
background: lightblue;
}
ul{
background: lightblue;
}