我想在javascript中获取img标签的图片地址
注意:我不想获取img标签的src属性
在 google chrome 中,如果您右键单击 img 标签,然后单击“复制图像地址”,chrome 将为您提供这样的地址
'http://127.0.0.1/mycms/images/img.jpg'
但是如果我使用这段代码
$('#myImgElement').attr('src');
jquery 给我这样的东西
../../images/img.jpg
我想提供图片地址,例如 google chrome 的“复制图片地址”,感谢您的帮助,如果我的文本中有语法问题,请原谅
最佳答案
可能是这样的:
console.log($('#test_img')[0].src) ;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img id="test_img" src="../../images/img.jpg"/>
关于javascript - 在 javascript 中给出 'image address' 的 img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51333054/