gpt4 book ai didi

jquery - 在 IE 中对通过 .load() 添加的 html 进行 jQuery 选择

转载 作者:行者123 更新时间:2023-12-01 05:09:53 25 4
gpt4 key购买 nike

场景:我使用 jQuery 延迟加载一些 html 并将所有 anchor 的相对 href 属性更改为绝对链接。

加载功能在所有浏览器中添加html。

url重写功能适用于所有浏览器中的原始DOM。

但是

在 IE7、IE8 中,我无法在 DOM 中新的延迟加载 html 上运行相同的函数。

//lazy load a part of a file
$(document).ready(function() {
$('#tab1-cont')
.load('/web_Content.htm #tab1-cont');
return false;
});
//convert relative links to absolute links
$("#tab1-cont a[href^=/]").each(function() {
var hrefValue = $(this).attr("href");
$(this)
.attr("href", "http://www.web.org" + hrefValue)
.css('border', 'solid 1px green');
return false;
});

我想我的问题是:让 IE 在使用 jQuery 延迟加载的 DOM 上进行选择的技巧是什么?

这是我的第一篇文章。温柔点:-)

谢谢

乔尔

最佳答案

您是否尝试过使用转换逻辑作为 load 的回调?

$(document).ready(function() {
$('#tab1-cont')
.load('/HeritageFoundation_Content.htm #tab1-cont', function(html){
$('a[href^=/]', html).each(function(){
var hrefValue = $(this).attr("href");
$(this)
.attr("href", "http://www.heritage.org" + hrefValue)
.css('border', 'solid 1px green');
return false;
});
});
return false;
});

关于jquery - 在 IE 中对通过 .load() 添加的 html 进行 jQuery 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2776172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com