通过将其他内容保持为静态来加载动态页面/内容
我希望通过将https://stackoverflow.com/questions/41733000/dynamic-page-content-loading-by-keeping-other-content-as-static/home.html页面保持为默认值来动态加载html页面,并且在加载另一个html页面时,div元素以外的内容应该是静态的。 我怎样才能实现它? 请帮忙。 我正在使用以下代码……
HTML代码
我的jquery代码是
$(document).ready(function(){ $('a').click(function(){ $('#dynamic').load('https://stackoverflow.com/questions/41733000/dynamic-page-content-loading-by-keeping-other-content-as-static/home.html'); return false; }); })
试试这种方法。 加载目标url应基于已单击的链接。
$(document).ready(function(){ $('nav a').click(function(event){ event.preventDefault(); $('#dynamic').load($(this).attr('href')); return false; }); })
请参阅示例jsfiddle 。
要加载锚点的href中指定的页面:
$('a').click(function(){ $('#dynamic').load(this.getAttribute('href')); return false; }