JavaScript图像src属性返回错误值 [英] Javascript image src attribute returns wrong value

查看:117
本文介绍了JavaScript图像src属性返回错误值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在按钮上附加了一些javascript代码,并在onclick上添加了以下代码:

I have a little javascript code attached to a button with onclick to the following code:

function ondelete () {

    var getDiv = document.getElementById("imgdiv");
    var lb_img = $("#imgdiv").children();
    for (var i = 0; i < lb_img.length; i++) {
        console.log(lb_img[i].src);
    }
}

这将返回一个很棒的输出,这是使用F12开发人员工具在chrome中打开时对应的html:

This returns a single output which is great, this is the corresponding html when opened in chrome with F12 developers tool:

<div id="imgdiv" class="modal-body next">
    <img draggable="false"src="http://(urlfrommywebsite)/A_LANX/get/OTc1/179f42">
</div>

因此,代码应返回该src属性,但应返回

So the code should return that src attribute, but instead it returns

http://127.0.0.1/stage/local/admin/galleries/gallery/2

这是我的网址.在其他图像上,它返回另一个img或同一URL的值,这确实很奇怪.这一切都发生在灯箱内部,因此没有打开灯箱的正常代码是

which is my url. On other images it returns the value of another img or this same url, really weird. This all happens inside a lightbox, so the normal code without a lightbox open is

<div id="imgdiv" class="modal-body next"></div>

我真的很困在这里,所以一点帮助真的很有用:)

I'm really stuck here, so a little help is really usefull :)

到目前为止,没有答案似乎对您有帮助,对其他带有诸如getImage()之类功能或类似功能的灯箱的建议?

No answer seems to help so far, any recommendations for other lightboxes with maybe a function like getImage() or something simular?

p.s. fancybox也不适合我.

p.s. fancybox doesn't quitte work for me either.

推荐答案

您可以尝试以下操作:

function ondelete() {

        var lb_img = $("#imgdiv").children();
        for (var i = 0; i < lb_img.length; i++) {
            console.log(lb_img[i].getAttribute("src"));
        }
    }

有关attr()和getAttribute()的更多信息,请参见以下文章: jQuery的attr()和getAttribute()

for more info about attr() and getAttribute() see this post:Difference between jQuery's attr() and getAttribute()

这篇关于JavaScript图像src属性返回错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆