gpt4 book ai didi

c# - 如何在母版页和内容(子)页中包含(引用)CSS Javascript jQuery

转载 作者:行者123 更新时间:2023-11-28 11:12:35 26 4
gpt4 key购买 nike

我有一个 HTML 模板,每个页面中都有很多 jQuery 和 CSS 引用,我正在尝试使用 master 但很难弄清楚要放什么以及将这些引用放在哪里,好消息是模板告诉我们哪些是全局级别的,哪些是页面级别的要求。

我试图将那些全局的东西放在母版页中,将那些子东西放在内容页中,但它们不起作用(显然 head 标签中的那些“STYLE”是有效的,但那些“SCRIPT ”在 body 标签的底部不是(我在网络浏览器的开发者模式下使用了“console”并得到了“Uncaught ReferenceError: jQuery is not defined”),还有一件事是SCRIPT 和 STYLE 中都有很多冗余引用,请建议我找到构建母版页和子页的最佳方法,如果你能给我一个母版页和内容页中的结构示例,那就太好了。

以下是 2 个原始 HTML 模板页面的示例:(我删除了正文中一些不必要的部分)以便您了解我要归档的内容。

Homepage.html

<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>Home</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />

<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<!-- END GLOBAL MANDATORY STYLES -->

<!-- BEGIN PAGE LEVEL PLUGIN STYLES -->
<link href="assets/plugins/fancybox/source/jquery.fancybox.css" rel="stylesheet" />
<link rel="stylesheet" href="assets/plugins/revolution_slider/css/rs-style.css" media="screen">
<link rel="stylesheet" href="assets/plugins/revolution_slider/rs-plugin/css/settings.css" media="screen">
<link href="assets/plugins/bxslider/jquery.bxslider.css" rel="stylesheet" />
<!-- END PAGE LEVEL PLUGIN STYLES -->

<!-- BEGIN THEME STYLES -->
<link href="assets/css/style-metronic.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/style.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/themes/blue.css" rel="stylesheet" type="text/css" id="style_color"/>
<link href="assets/css/style-responsive.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/custom.css" rel="stylesheet" type="text/css"/>
<!-- END THEME STYLES -->

<link rel="shortcut icon" href="favicon.ico" />
</head>
<!-- END HEAD -->

<!-- BEGIN BODY -->
<body>

<!-- SOME BODY CONTENTS -->

<!-- Load javascripts at bottom, this will reduce page load time -->
<!-- BEGIN CORE PLUGINS(REQUIRED FOR ALL PAGES) -->
<!--[if lt IE 9]>
<script src="assets/plugins/respond.min.js"></script>
<![endif]-->
<script src="assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="assets/plugins/hover-dropdown.js"></script>
<script type="text/javascript" src="assets/plugins/back-to-top.js"></script>
<!-- END CORE PLUGINS -->

<!-- BEGIN PAGE LEVEL JAVASCRIPTS(REQUIRED ONLY FOR CURRENT PAGE) -->
<script type="text/javascript" src="assets/plugins/fancybox/source/jquery.fancybox.pack.js"></script>
<script type="text/javascript" src="assets/plugins/revolution_slider/rs-plugin/js/jquery.themepunch.plugins.min.js"></script>
<script type="text/javascript" src="assets/plugins/revolution_slider/rs-plugin/js/jquery.themepunch.revolution.min.js"></script>
<script type="text/javascript" src="assets/plugins/bxslider/jquery.bxslider.min.js"></script>
<script src="assets/scripts/app.js"></script>
<script src="assets/scripts/index.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
App.init();
App.initBxSlider();
Index.initRevolutionSlider();
});
</script>
<!-- END PAGE LEVEL JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>

Contact.html

<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>Contacts</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />

<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<!-- END GLOBAL MANDATORY STYLES -->

<!-- BEGIN PAGE LEVEL PLUGIN STYLES -->
<link href="assets/plugins/fancybox/source/jquery.fancybox.css" rel="stylesheet" />
<!-- END PAGE LEVEL PLUGIN STYLES -->

<!-- BEGIN THEME STYLES -->
<link href="assets/css/style-metronic.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/style.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/themes/blue.css" rel="stylesheet" type="text/css" id="style_color"/>
<link href="assets/css/style-responsive.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/custom.css" rel="stylesheet" type="text/css"/>
<!-- END THEME STYLES -->

<link rel="shortcut icon" href="favicon.ico" />
</head>
<!-- END HEAD -->

<!-- BEGIN BODY -->
<body>

<!-- SOME BODY CONTENTS -->

<!-- Load javascripts at bottom, this will reduce page load time -->
<!-- BEGIN CORE PLUGINS(REQUIRED FOR ALL PAGES) -->
<!--[if lt IE 9]>
<script src="assets/plugins/respond.min.js"></script>
<![endif]-->
<script src="assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="assets/plugins/hover-dropdown.js"></script>
<script type="text/javascript" src="assets/plugins/back-to-top.js"></script>
<!-- END CORE PLUGINS -->

<!-- BEGIN PAGE LEVEL JAVASCRIPTS(REQUIRED ONLY FOR CURRENT PAGE) -->
<script type="text/javascript" src="assets/plugins/fancybox/source/jquery.fancybox.pack.js"></script>

<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
<script src="assets/plugins/gmaps/gmaps.js" type="text/javascript"></script>
<script src="assets/scripts/contact-us.js"></script>
<script src="assets/scripts/app.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
App.init();
ContactUs.init();
});
</script>
<!-- END PAGE LEVEL JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>

最佳答案

最大的问题是我没有意识到代码的ORDER 很重要,很重要,无论您将那些STYLESCRIPT 放在哪里在母版页或子页中,它们必须完全按照您的 HTML 模板中的顺序排列(例如:全局事物必须在那些页面级事物之前呈现......)。我跟着它,它现在工作了。

这里是我做的基本母版页结构:

<!-- BEGIN HEAD -->
<head id="Head1" runat="server">

<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="~/assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="~/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- END GLOBAL MANDATORY STYLES -->

<asp:ContentPlaceHolder ID="Head" runat="server">

//Put your PAGE REQUIRED STYLE HERE in your content (child page)

</asp:ContentPlaceHolder>

<!-- BEGIN THEME STYLES -->
<link href="~/assets/css/style-metronic.css" rel="stylesheet" type="text/css" />
<link href="~/assets/css/style.css" rel="stylesheet" type="text/css" />
<link href="~/assets/css/themes/red.css" rel="stylesheet" type="text/css" id="style_color" />
<link href="~/assets/css/style-responsive.css" rel="stylesheet" type="text/css" />
<link href="~/assets/css/custom.css" rel="stylesheet" type="text/css" />
<!-- END THEME STYLES -->

<link rel="shortcut icon" href="favicon.ico" />

<!-- END HEAD -->
</head>

<!-- BEGIN BODY -->
<body>

// PUT WHAT EVER YOU WANT TO PUT HERE
// PUT WHAT EVER YOU WANT TO PUT HERE

<!-- Load javascripts at bottom, this will reduce page load time -->
<!-- BEGIN CORE PLUGINS(REQUIRED FOR ALL PAGES) -->
<!--[if lt IE 9]>
<script src="/assets/plugins/respond.min.js"></script>
<![endif]-->
<script src="/assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="/assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="/assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/assets/plugins/hover-dropdown.js"></script>
<script type="text/javascript" src="/assets/plugins/back-to-top.js"></script>
<!-- END CORE PLUGINS -->

<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">

//Put your PAGE REQUIRED SCRIPT HERE in your content (child page)

</asp:ContentPlaceHolder>
</div>

// PUT WHAT EVER YOU WANT TO PUT HERE
// PUT WHAT EVER YOU WANT TO PUT HERE

</body>
<!-- END BODY -->
</html>

关于c# - 如何在母版页和内容(子)页中包含(引用)CSS Javascript jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21913191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com