Hy,我是html的新手,我正在尝试制作一个带有菜单的网站。该网站有更多的页面,所以我必须复制所有页面上的菜单。我想问你的是,没有其他方法可以导入菜单(例如从menu.html页面导入),这样我就不会被迫复制粘贴它?
创建一个menu.html页面,并将所有菜单项包括在此页面中,然后
<!--#include file="menu.html"-->
这将为你完成任务。将两个文件保存在同一目录中。
您需要使用母版页。
这是你的主页:
<%@ Master Language="C#" AutoEventWireup="true"
CodeBehind="Site.master.cs" Inherits="Demos.Site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
***<asp:Label ID="Label1" runat="server"
Text="Your Content Here:" />***
<asp:ContentPlaceHolder
ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
标签将显示在使用此母版页的所有页面中将要更改的是"ContentPlaceHolder1"中的内容
这是我们的html页面:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="myContentPage.aspx.cs"
Inherits="Demos.myContentPage" %>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" Text="This is from the content page"
BackColor="YellowGreen" runat="server" />
</asp:Content>
请在此处阅读:http://webmaster.org.il/articles/aspnet-masterpage
http://msdn.microsoft.com/en-us/library/wtxbf3hh.ASPX
如果您是web开发的初学者。使用IFRAME很容易。
示例
<!DOCTYPE html>
<html>
<body>
<!-- Your menu-->
<a href="http://www.w3schools.com" target="iframe_a">W3Schools</a>
<a href="http://www.google.com" target="iframe_a">Google</a>
<a href="http://www.yahoo.com" target="iframe_a">Yahoo</a>
<!--menu end-->
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
</body>
</html>
浏览W3school以供参考。。。所有最好的
如果使用jquery添加到HTML <div id="menu"></div>
和javascript
$(function(){ $( "#menu" ).load( "menu.html" ); })
在menu.html
内部构建菜单。
对于css,使用外部css