单击将 a) 滚动到 div,b) 打开所述 div,c) 将 html 从另一个页面加载到该 div 中。如何?

发布于 2024-09-28 21:27:30 字数 396 浏览 2 评论 0原文

我已经有了“滚动到”和切换功能:

$("a.view").click(function(){
    $("#content").slideToggle("slow");
    return false;
});

并且滚动是通过 这个方便的小插件。

现在我如何从另一个页面加载一些 html 到这个新打开的名为 #content 的 div 中。我到处尝试了一些东西,但似乎无法让它发挥作用。

有什么想法吗?

I already have the "scroll to" and toggle functions in place:

$("a.view").click(function(){
    $("#content").slideToggle("slow");
    return false;
});

And the scrolling is taken care of via this handy little plugin.

Now how do I load some html from another page into this newly opened div called #content. I've tried a few things here and there but just can't seem to get it to work.

Any ideas please?

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

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

发布评论

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

评论(1

天暗了我发光 2024-10-05 21:27:30

使用 jQuery 非常简单。

$('#content').load('path/file.html', function() {
   // done
});

您还可以“部分”加载数据,例如

$('#content').load('path/file.html #container', function() {
   // done
});

仅加载 file.html 中 id 为“#container”的元素。

参考:.load()

Pretty trivial using jQuery.

$('#content').load('path/file.html', function() {
   // done
});

You may also "partial" load data, for instance

$('#content').load('path/file.html #container', function() {
   // done
});

will only load the element with the id `#container' out of file.html.

Ref.: .load()

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