我有一段像这样的离线 html:
<img src="../img/button.png"/>
当我尝试访问 JS 中的 src 属性时,我得到的值与 html 中所写的值不同:
var s = myimg.src; // equals 'file:///V:/test/test1/img/button.png'
就好像值在 html 和我对“src”属性的调用之间的某处得到了解析。如何获得“原始”值而不是解析后的值?
发送
最佳答案
使用getAttribute
var s = myimg.getAttribute('src')
关于javascript - 如何在javascript中从img src获取 "real"url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6966402/