[英]load jqmobile.js file for only one page and remove it for other pages
我的桌面应用程序有一个表,其中包含使用JQmobile格式创建的原始页面(因为它也用在移动设备上)。 当我为该过程调用任何原始页面时,我当然会加载JQmobile.js文件。 问题是,当我尝试调用其他桌面页面时,仍会加载JQmobile.js,因此所有后续桌面处理请求均以JQmobile格式运行。 我如何才能仅针对适当的处理加载此JQmobile.js文件,然后在后续的后续桌面处理请求的其余部分中将其删除?
to be more specific, I have a 2 bundles like this:
bundles.Add(new ScriptBundle("~/bundles/Mbsa_JSBundle").Include(
"~/Scripts/mbsa_Mobile.js",
"~/ScriptJQMobile-145/jquery.mobile-1.4.5/jquery.mobile-1.4.5.js"
));
bundles.Add(new StyleBundle("~/Content/Mbsa_CSSBundle").Include(
"~/Content/mbsa_Mobile.css",
"~/Content/MbsaMobileStandardCSS/jquery.mobile.icons.min.css",
"~/ScriptJQMobile-145/jquery.mobile-1.4.5/jquery.mobile.structure-`1.4.5.css",`
"~/Content/MbsaMobileStandardCSS/MbsaMobileStandard.css"
));
使用给我答案的用户示例。 我很想做这样的事情。 (但这是within another script tag).
<body id="pagetag"></body>
<script>
if($('body').is('#pagetag')){
if($('body').is('#pagetag')){
@Styles.Render("~/Content/Mbsa_CSSBundle")
@Scripts.Render("~/bundles/Mbsa_JSBundle")
}
})
</script>
// This works ok, but as stated, the scripts remain even
// when a non jqmobile formated page is requested.
@if ((bool)Session["Mbsa-IsMobile"] == false)
{
@Styles.Render("~/Content/Mbsa_DMCSSBundle")
@Scripts.Render("~/bundles/Mbsa_DMJSBundle")
}
转到非jqmobile格式的页面后,如何删除这些捆绑包?
向正文添加id或class
<body id="pagetag">
然后添加一个脚本
$(function(){
if($('body').is('#pagetag')){
// add whatever scripts you need
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.