首先,我希望每个人都知道我是绝对的初学者所以请耐心等待我.
我想知道如何将整个html页面放在div中.我试过$("#footballPlayers").html("footballplayers.html");但它显示footballplayers.html文本而不是整个页面.
<html>
<head>
<script type="text/javascript" src="jquery1.6.4min.js"></script>
<script type="text/javascript">
$(function(){
$("div#tabFootballPlayers").click(function(){
$("#footballPlayers").html("footballplayers.html");
$("#actionStars").html("");
$("#directors").html("");
});
});
$(function(){
$("div#tabActionStars").click(function(){
$("#actionStars").html("actionstars.html");
$("#footballPlayers").html("");
$("#directors").html("");
});
});
$(function(){
$("div#tabDirectors").click(function(){
$("#directors").html("directors.html");
$("#actionStars").html("");
$("#footballPlayers").html("");
});
});
</script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div>
<div id="tabFootballPlayers">Football Players</div>
<div id="footballPlayers"> </div>
<div id="tabActionStars">Action Stars</div>
<div id="actionStars"> </div>
<div id="tabDirectors">Directors</div>
<div id="directors"> </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
你使用的.load()功能:
$("#footballPlayers").load('footballplayers.html body');
Run Code Online (Sandbox Code Playgroud)
请注意URL后面的选择器.您可以从该页面中选择元素.我认为你需要body,因为嵌套<html>标签可能会很糟糕.
关于您的代码的一些评论:
您不要多次使用此功能.只需将所有代码推入其中:
$(function() {
// All of your code here.
});
Run Code Online (Sandbox Code Playgroud)
我更喜欢这种语法,因为它看起来更实用,并向您展示它的作用:
$(document).ready(function() {
// All of your code here.
});
Run Code Online (Sandbox Code Playgroud)
此外,您的代码实际上是多余的.尝试冷凝它:
$(document).ready(function() {
$("#your_menu_container div").click(function() {
$(this).load(this.id.substr(3).toLowerCase() + '.html').siblings().html('');
});
});
Run Code Online (Sandbox Code Playgroud)
使用负载
jQuery("#footballPlayers").load("footballplayers.html");
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请单击此处
更换
$("#directors").html("directors.html");
Run Code Online (Sandbox Code Playgroud)
同
$("#directors").load("directors.html");
Run Code Online (Sandbox Code Playgroud)
您加载应该只包含DIV的内容的HTML文件-即没有<head>的<body>,甚至导航-只是内容
| 归档时间: |
|
| 查看次数: |
25653 次 |
| 最近记录: |