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 oArributeNode is "+oAttributeNode.nodeType);
console.log('The length of oDiv1 is '+oDiv1.childNodes.length);
var oTextNode=oDiv1.childNodes[0];
console.log("The textcontent of childNodes[0] is"+oDiv1.childNodes[0].textContent);
console.log("The node type of oArributeNode is "+oTextNode.nodeType);
console.log("childNodes[1] is "+oDiv1.childNodes[1].textContent);
console.log(oDiv1.childNodes[1].tagName);
console.log("childNodes[2] is "+oDiv1.childNodes[2].textContent);
console.log("The node type of childNodes[1] is "+oDiv1.childNodes[1].nodeType);
console.log("The node type of childNodes[2] is "+oDiv1.childNodes[2].nodeType);
console.log(oDiv1.childNodes[1].tagName);
console.log(oDiv1.childNodes[1].childNodes[0].nodeValue);
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 oLisInul1=oUls[0].getElementsByTagName('li');
var oLisInDoc=document.getElementsByTagName('li');
console.log('The length of oLisInul1 is '+oLisInul1.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 oRadios1=oDivs[2].getElementsByClassName('radio');
console.log('The length of oRadios1 is '+oRadios1.length);
var oInputFemale=document.querySelector("input:checked");
console.log("line 70:"+oInputFemale.value);
var oInputs=document.querySelectorAll("input");
console.log("line 73:"+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="red";
oList2Lis[2].style.color="green";
var oNamedRadios=document.getElementsByName("gender");
console.log("Line 94:"+oNamedRadios[0].value);
oNamedRadios[1].checked=true;
var oFruits=document.getElementsByName("fruit");
console.log("Line 98:"+oFruits[0].value);
oFruits[0].checked=true;
console.log(document.title);
console.log(document.body.tagName);
console.log(document.body.childNodes.length);
var oFynamicButton=document.createElement("button");
var oTextNode=document.createTextNode("替换");
oFynamicButton.appendChild(oTextNode);
document.body.appendChild(oFynamicButton);
document.body.insertBefore(oFynamicButton,oUls[0]);
oFynamicButton.onclick=function(){
var oDiv1=document.getElementById("Div1");
var oPH1=document.createElement("p");
var oPText=document.createTextNode("Hi");
oPH1.appendChild(oPText);
oDiv1.replaceChild(oPH1,oDiv1.childNodes[1]);
}
console.log("line 138:The id of oDiv1:"+oDiv1.id);
console.log("line 139:The id of oDiv1:"+oDiv1.getAttribute("id"));
console.log("line 140:The data of oDiv1:"+oDiv1.data);
console.log("line 141:The data of oDiv1:"+oDiv1.getAttribute("data"));
console.log("line 142:The class of oDiv1:"+oDiv1.className);
var oInput=document.getElementById("insertInput");
oInput.setAttribute("value","enter");
if(oInput.hasAttribute("value")){
console.log("value is the attribute of oInput");
}
oInput.removeAttribute("value");
if(oInput.hasAttribute("value")){
console.log("value is the attribute of oInput");
}
oUls[0].removeAttribute("class");
console.log("line 168:The class of oUls[0]:"+oUls[0].className);
}
function insertChild(){
var oInput=document.getElementById("insertInput");
var strValue=oInput.value;
console.log(strValue);
var oList1=document.getElementById("List1");
var oLis=document.getElementsByTagName("li");
var oCreatedLi=oLis[0].cloneNode(true);
oCreatedLi.textContent=strValue;
oList1.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;
console.log(strValue);
var oList1=document.getElementById("List2");
var oLis=document.getElementsByTagName("li");
var oCreatedLi=oLis[0].cloneNode(true);
oCreatedLi.textContent=strValue;
oList1.appendChild(oCreatedLi,oLis[1]);
}
function removeButton() {
var oList2 = document.getElementById("List2");
var oLis = oList2.getElementsByTagName("li");
oList2.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>
<button onclick="removeTop()">删除列表元素顶部</button>
<ul id="List2" class="list">
<li> Vue </li>
<li> React </li>
<li> Angular </li>
</ul>
<input id="appendInput" type="text"></input>
<button onclick="appendToList()">添加到列表元素的尾部</button>
<button onclick="removeButton()">删除列表元素的尾部</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>
.list {
background-color: lightblue;
};