繁体   English   中英

使用jquery将html文件中的内容加载到div中

[英]Loading a content from html file with jquery into a div

所以我试图从另一个 html 文件填充主要内容 div。

我有这样的前两个链接:

<a href="" class="load-page" data-location="./content/johdanto.html">Johdanto</a>
<a href="" class="load-page" data-location="./content/vastuualueet.html">Vastuualueet</a>

和主要内容div设置如下:

<div class="main" id="content">

jquery是这样的

$('.load-page').on('click', function(event)
{event.preventDefault();
$('#content').load($(this).data('location'));
});

填充 div 有效,但无论我单击哪个链接,它都只会加载第一个文件,需要一些帮助:(

如果有人遇到这种情况

$('.load-page').on('click', function(event)
{event.preventDefault();
$.ajaxSetup({ cache: false });
$('#content').load($(this).data('location'));
});

将缓存设置为 false 为我修复了它:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM