我已经从来没有在此之前使用jQuery,但我会解释我正在尝试做什么。jQuery.load加载HTML文件
的index.html
<!DOCTYPE html>
<html>
<head>
<title>My Awesome Website</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" href="/favicon.ico" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<!-- <iframe width="100%" height="175" frameborder="0" scrolling="no" src="navbar.html"></iframe> I used to use this - but i cant have dropdown menus. -->
<!-- This is my problem -->
<script>
$('#navbar').load('./navbar.html');
</script>
<noscript>
<h1>Please enable Javascript!</h1>
</noscript>
<div id="container">
<!-- Content Here -->
</div>
</body>
</html>
navbar.html
<div id="navbar">
<li><object width="64" height="64" data="favicon.svg" type="image/svg+xml"></object></li>
<li><object width="64" height="64" data="icons/tech.svg" type="image/svg+xml"></object></li>
<li><object width="64" height="64" data="icons/games.svg" type="image/svg+xml"></object></li>
<li><object width="64" height="64" data="icons/contact.svg" type="image/svg+xml"></object></li>
</div>
所以我想在这里做的,是有很多的HTML页面,所有链接一个navbar html页面,所以当我更改navbar.html时,我不必更改每个页面。
我已经有了另一个问题here。 Davor Milnaric建议“如果您使用的是jQuery,您可以使用'.load()'函数。api.jquery.com/load”来尝试,但我无法使它工作。我究竟做错了什么?我如何解决它?任何帮助将非常感激。
嗨,谢谢你的回复。 :)当我尝试这个,没有改变,导航栏仍然不加载...任何想法? – Yharooer