object.src和object.getAttribute('src')之间的区别 [英] Difference between object.src and object.getAttribute('src')
本文介绍了object.src和object.getAttribute('src')之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,这是一个示例HTML代码:
So, here is an example HTML code:
<img src="test.png" id="test">
这是一个Javascript代码:
And here is a Javascript code:
element = document.getElementById('test');
alert(element.getAttribute('src')); --> test.png
alert(element.src); --> domain.com/test.png
为什么getAttribute不显示域,而.src是,它将添加域?在哪里可以找到在DOM对象中访问属性的不同方式之间的区别?
Why would getAttribute not show the domain, while .src yes, it adds the domain? Where can I find the difference between the different ways of accessing attributes in a DOM object?
推荐答案
You can see the difference in the HTML specification as "permitted attributes" versus "DOM interface".
查看全文