admin管理员组文章数量:1336631
I have piece of offline html like so:
<img src="../img/button.png"/>
and when I try to access the src attribute in JS, I get a different value than what's written in the html:
var s = myimg.src; // equals 'file:///V:/test/test1/img/button.png'
It's as if the value got resolved somewhere between the html and my call to 'src' attribute. How do I get the "original" value instead of the resolved one?
tnx
I have piece of offline html like so:
<img src="../img/button.png"/>
and when I try to access the src attribute in JS, I get a different value than what's written in the html:
var s = myimg.src; // equals 'file:///V:/test/test1/img/button.png'
It's as if the value got resolved somewhere between the html and my call to 'src' attribute. How do I get the "original" value instead of the resolved one?
tnx
Share Improve this question asked Aug 6, 2011 at 11:09 Sagi MannSagi Mann 3,6209 gold badges44 silver badges83 bronze badges2 Answers
Reset to default 6use getAttribute
var s = myimg.getAttribute('src')
If you read the attribute instead of the src
property, you get the original value:
var s = myimg.getAttribute('src');
本文标签: htmlhow to get quotrealquot url from img src in javascriptStack Overflow
版权声明:本文标题:html - how to get "real" url from img src in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742380047a2463921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论