jquery自动映像重载在src属性更新? [英] jquery automatic image reload on src attribute update?

查看:61
本文介绍了jquery自动映像重载在src属性更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个像这样的html字符串:

Suppose I have an html string like so :

var string = '<div><img src="foo/bar" /></div>';

我选择它的图像部分如下:

and I select the image part of it like so :

var $img = $(string).find('img');

然后我更改'src'属性:

and then I change the 'src' attribute :

$img.attr('src', 'foo2/bar2');

这会在新的'src'触发自动AJAX get请求吗?我在我的代码中出现了一个流氓GET错误,当我在上面注释掉这一行时,它会消失,但也许它来自其他地方。

Does this trigger an automatic AJAX get request at the new 'src'? I'm getting a rogue GET error in my code that goes away when I comment out the line above, but maybe it's coming from somewhere else.

如果这实际上是来自Jquery,有没有办法关闭或阻止AJAX请求?我试过.stopPropogation()没有任何运气...

If this is in fact coming from Jquery, is there a way to turn off or block the AJAX request? I've tried .stopPropogation() without any luck...

推荐答案

以防 $ img 是一个真正的dom elemnt(存在于你的html中) - get reqest将会触发。

如果 $ img 不是你不会触发获取请求但你仍然可以通过以下方式触发:

in case that $img is a real dom elemnt (exists in your html) - a get reqest will fire.
if $img is not you won't trigger a get request but you can still trigger it by:

$img[0].src = '/foo/bar'

阻止浏览器呈现图像的唯一方法是停止它:

the only way you can stop a browser from rendering images is by stopping it:

if(window.stop !== undefined)
  window.stop();    
else if(document.execCommand !== undefined)
  document.execCommand("Stop", false);

这篇关于jquery自动映像重载在src属性更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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