jquery load() 在 IE8 中根本不起作用

发布于 2024-12-01 13:27:07 字数 443 浏览 0 评论 0原文

谷歌充满了这个问题,但其他页面都没有帮助我。

我尝试过更改 jquery 版本,尝试执行整个 var $j = jQuery.noConflict();,尝试重新排列 JS/jquery 脚本,尝试 jquery 网站建议的无缓存功能,但我的 load() 仍然不起作用。

<a onclick="loadCont('canyou.php');">Can you help us</a>


function loadCont(file){
$j("#maincont").load(file);
alert(file);
return false;
}

与往常一样,它可以在除 IE8 之外的所有其他浏览器上加载。 alart() 用于 IE8 调试,并且文件已成功传递,只是未加载到 #maincont

任何有关代码或回复的帮助表示赞赏。 谢谢

Google is full of this question but none of the other pages help me.

I've tried changing jquery versions, tried doing the whole var $j = jQuery.noConflict();, tried rearranging JS/jquery scripts, tried the no caching thing suggested by jquery website but still my load() doesn't work.

<a onclick="loadCont('canyou.php');">Can you help us</a>


function loadCont(file){
$j("#maincont").load(file);
alert(file);
return false;
}

As always it loads on every other browser except IE8. The alart() is there for IE8 debugging, and the file is passed successfully, its just not loaded into #maincont

Any help aboutthe code or replies appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ㄟ。诗瑗 2024-12-08 13:27:07

尝试稍微不同地设置它。使用以下代码并查看是否得到任何结果。

HTML

<!-- link with ajax target in href -->
<a class="loadlink" href="canyou.php">Can you help us</a>

jQuery

<html>
<head><title>can you</title></head>
<body>
    <!-- we only want to load content from this div -->
    <div id="content">This is the only content we want returned...</div>
</body>
</html>

EDIT

如果 canyou.php 包含带有 标签的完整 html 框架,那么您应该有 jQuery 解析仅从该页面中取出您想要的 HTML 并丢弃其余部分(您不想将 标记推入 #maincont分区)。您可以让 jQuery 通过在 load() 方法中的 URL 参数后面添加一个空格然后添加一个选择器来实现此目的。以下是 HTML 示例:

<html>
<head><title>can you</title></head>
<body>

    <div id="content">
        This is the only content we want returned...
    </div>
</body>
</html>

新的加载调用如下所示:

$('#maincont').load($(this).attr('href') + ' #content');    // Only get the content in #content div

Try setting this up a little differently. Use the following code and see if you get any results.

HTML

<!-- link with ajax target in href -->
<a class="loadlink" href="canyou.php">Can you help us</a>

jQuery

<html>
<head><title>can you</title></head>
<body>
    <!-- we only want to load content from this div -->
    <div id="content">This is the only content we want returned...</div>
</body>
</html>

EDIT

If canyou.php contains a full html skeleton with <html> and <body> tags then you should have jQuery parse out only the HTML you want from that page and discard the rest (you don't want to shove <html> or <body> tags into your #maincont div). You can have jQuery do this by adding a space then a selector after the URL parameter in the load() method. Here's an example of the HTML:

<html>
<head><title>can you</title></head>
<body>

    <div id="content">
        This is the only content we want returned...
    </div>
</body>
</html>

Here's what the new load call would look like:

$('#maincont').load($(this).attr('href') + ' #content');    // Only get the content in #content div
提笔落墨 2024-12-08 13:27:07

哟兄弟。你忘记了 e.preventDefault();

如果您想在当前页面的 div 中打开一个链接,例如:

您能帮忙吗us

您的 jQuery 应该如下所示::

$("a.loadlink").click(function(e){
e.preventDefault(); //this prevents the redirect that the <a> tag makes on default

// then enter the rest of your jQuery here:
var file = $(this).attr("href");
$("#maincont").load(file);
});

这应该可以“即插即用”工作。

Yo Bro. You forgot e.preventDefault();

If you want to have a link open up in a div on your current page, for ex:

<a class="loadlink" href="canyou.php">Can you help us</a>

Your jQuery should look like this::

$("a.loadlink").click(function(e){
e.preventDefault(); //this prevents the redirect that the <a> tag makes on default

// then enter the rest of your jQuery here:
var file = $(this).attr("href");
$("#maincont").load(file);
});

That should work 'plug-n-play'.

与往事干杯 2024-12-08 13:27:07

$(. 之间的字母 j 正常吗?

不是 $("#maincont").load(file );

我使用 IE8 的 load...个人感觉效果很好

the letter j between $ and (. is it normal ?

is it not $("#maincont").load(file);

I use load with IE8... it works good personally

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文