过去几天我一直在研究这个问题,但无法弄清楚。下面的代码根据当前页面类在外部文件中搜索内容,然后将内容加载到页面上任何匹配的 ID 中。它适用于 Chrome、Firefox、IE9,但最近停止在 IE8 中运行,我不知道为什么。任何想法将不胜感激。
HTML 看起来像这样
<body class="jms">
<div id="mainHomeContent" class="shared"></div>
</body>
jquery 准备就绪
$("div.shared").each(function(){
var Body = $(document).find("body");
var contentID = ("#" + $(this).attr("id"));
var pathname = ""
if(Body.hasClass("pigman")){
var pathname = "/dev/jmsracing/content/pigman/shared-content-include.html"
} else if(Body.hasClass("marion-arts")){
var pathname = "/dev/jmsracing/content/marion-arts/shared-content-include.html"
} else if(Body.hasClass("jms")){
var pathname = "/dev/jmsracing/content/jms/shared-content-include.html"
alert('hello');
}
$(contentID).load(pathname + " " + contentID);
});