$(html)
使得jQuery实际上将html代码注入隐藏页面的某处,以便计算宽度,高度,样式,距离,属性等。此操作始终使用浏览器的内置DOM解析器,这就是图像,iframe,背景图像,脚本,链接等被访问的原因。
您可以使用$.parseXML(html);
但html代码需要有效格式化xml(xhtml)。
如果你唯一担心的是图像,但是你可以使用此代码:
// take the src attribute, change it to hiddensrc
// credits: http://stackoverflow.com/a/1310706/608886
var html = html.replace(/<img([^>]*)\ssrc=(['"])(?:[^\2\/]*\/)*([^\2]+)\2/gi,
"<img$1 hiddensrc=$2$3$2");
// parse the code
var parsed = $(html);
///////////////
//
// do whatever you want here
//
//////////////
// put the src attribute back at your discretion
parsed.find(img[hiddensrc]).each(function(){
$(this).attr('src',$(this).attr('hiddensrc'));
});
你应该检查src属性,然后将其设置为null – 2012-07-12 14:08:34