简体   繁体   English

如何在jQuery中删除img标签的URL?

[英]How to remove the url for an img tag in jquery?

I need to empty an img tag from it is own image but keeping the img tag empty on the page. 我需要从其自身图像中清空img标签,但将img标签保留在页面上为空。

I use this code with no success. 我使用此代码没有成功。 Any idea what is wrong here? 知道这里有什么问题吗?

var img = $('<img id="'+ scope.elmItem +'">');
    img[0].src = '';

Combining jQuery object and pure JS properties in such manner can result in many things, most of them not working the way you want it... Try something like this: 以这种方式组合jQuery对象和纯JS属性可能会导致很多事情,其中​​大多数都无法按照您想要的方式工作...尝试如下操作:

$('img#'+ scope.elmItem).attr('src', '');

Or the pure JS approach: 或纯JS方法:

document.getElementById(scope.elmItem).src = ''

Just stick to one and you'll be good to go. 坚持下去,您将一路顺风。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM