Set out to
<html>
<head>
<title>About access to important information in the document</title>
</head>
<body>
</body>
</html>
以上是简单的框架。
开干!
var getDocument = document.documentElement; //这里是通篇文档的获取。
var getFirstNode = document.firstChild; //获取第一个子元素
var getFirstElement = document.childNode[0];
/*
if(getFirstNode == getFirstElement){
console.log("ture");
}
*/
其实getFirstNode
就是 getFirstElement
OK,接下来就是获取整个页面的body
元素了.
var getBodyElement = document.body;//HTMLBodyElement.
既然body
搞定了,就开始更改title
了。
和获取body元素方法一模一样。
//那我们改一下标题.
getTitle.title = "change the title.";
看一下CSDN所传过来的URL是什么
//直接在console.log调试台里面就可以看到了.
documet.URL="www.CSDN.net";//的确就改了"www.csdn.net"
Since access to the URL, then try to zhihu on image capture all over again.
var getElementImg = document.getElmentsByTag("img");
alert(getElementImg.length); //查看有多少img
我返回的是7,url是:https://www.zhihu.com/topic/19551432这个。
看一下第一个图像的特性是多少?heihei.
var getImg = document.getElementsByTagName("img");
console.log(getImg[0].src); //https://pic1.zhimg.com/da8e974dc_s.jpg
//看看它的ID是怎么样的。
console.log(getImg[0].id);//由于没有写id所以就没有返回值。
More nausea, add an element that becomes more powerful, for the javascript programming language.
var writeElement = document.writeln("<p>"+"hello world"+"</p>");//瞬间改名为hello world.痛苦啊!!
//现在用纯javascript创建元素,绝笔简单.
var NewElement = document.createElement("div"); //一定要调用文档中的createElement();
NewElement.id = "myDiv";
//同样也可以写:
NewElement.setAttribute("id","changeID");
NewElement.innerHTML = "test";
//也有不同的创建文本的方式
var text = document.createTextNode("changeTest"); //这个还有些复杂.
NewElement.appendChild(text); //这就添加了一个子节点
document.body.appendChild(NewElement); //这就添加完成了一个div元素.
以后特性再更新.