參考鏈接:
1、https://www.w3cschool.cn/javascript/3fnbpf21.html
2、https://www.w3cschool.cn/jsref/jsref-event-onkeydown.html
3、https://www.w3cschool.cn/jsnote/jfm81pvw.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body onload="checkCookie()" onunload="unloadBody()">
<div id="myDIV1">
<p id="demo">This is paragraph.</p>
<p id="showCookie"></p>
<button onclick="document.getElementById('demo').style.visibility = 'hidden'">Hide</button>
<button onclick="document.getElementById('demo').style.visibility = 'visible'">Show</button>
<button onclick="removeAllA()">removeA</button>
<br>
<a id="baidulink" href="https://www.baidu.com">Baidu</a>
<a id="google" href="https://www.google.com">google</a>
<a id="hao123" href="https://www.hao123.com">hao123</a>
<br>
</div>
<!-- next is javascript -->
<script text="text/javascript">
document.getElementById("demo").onmouseover = function () { document.getElementById("demo").style.color = "#FF0000"; }
document.getElementById("demo").onmouseout = function () { document.getElementById("demo").style.color = "#C0C0C0"; }
function unloadBody() {
alert("You will leave Body!");
}
function checkCookie()
{
if(navigator.cookieEnabled == true)
{
document.getElementById("showCookie").innerHTML = "Cookie can use!";
}
else
{
document.getElementById("showCookie").innerHTML = "Cookie can not use!";
}
}
// add DOM
var domP = document.createElement("p");
var domPtxt = document.createTextNode("this is create by JS!");
domP.appendChild(domPtxt);
document.getElementById("myDIV1").appendChild(domP);
// delete DOM
var divPara = document.getElementById("myDIV1");
var alinkPara0 = document.getElementById("baidulink");
var alllink = document.getElementsByTagName("a");
//divPara.removeChild(alinkPara0);
// remove all tag <a></a>
function removeAllA()
{
var myLen = alllink.length;
for (var i = 0; i < myLen; i++) {
divPara.removeChild(alllink[0]);// alllink whill change
}
}
</script>
</body>
</html>