Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

document.getElementById("**").src是绝对路径还是相对路径?

设 var x = document.getElementById("*").src,
return x得到的是绝对路径
但是document.getElementById("*").src=某个相对路径却可以?
谢谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

需要了解的概念:gettersetter
getter用于读取属性,setter用于写入属性。虽然这俩是ES6的东西,但是并不妨碍浏览器内部的实现~
var x = document.getElementById("img").src相当于读取src属性,document.getElementById("img").src="XXX"相当于写入,这俩实际是分开的:在写入的时候,浏览器既可以接受绝对路径、也可以接受相对路径;但在读取的时候,只会给你返回个(翻译好的)绝对路径。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...