【问题标题】:how to to check if jQuery is loaded from C# code?如何检查是否从 C# 代码加载了 jQuery?
【发布时间】:2012-07-29 08:03:56
【问题描述】:

我正在开发一个 WEB_PART,我想知道是否有某种方法可以找出要插入 Web 部件的母版页项目中是否存在任何 JQUERY LIB。

我想做这样的事情:

  if (jQuery) {  
 // jQuery is loaded  
Page.ClientScript.RegisterClientScriptInclude(typeof(WebpartSlideShow), "jQuery",                        "/_layouts/Jquery-Cycle/jquery-1.5.1.min.js");
Page.ClientScript.RegisterClientScriptInclude(typeof(WebpartSlideShow), "jQueryCycle", "/_layouts/Jquery-Cycle/jquery.cycle.all.min.js");
               // break;
   } else {
  // jQuery is not loaded
    Page.ClientScript.RegisterClientScriptInclude(typeof(WebpartSlideShow), "jQueryCycle", "/_layouts/Jquery-Cycle/jquery.cycle.all.min.js");

  }

【问题讨论】:

    标签: c# jquery jquery-ui sharepoint web-parts


    【解决方案1】:

    http://msdn.microsoft.com/en-us/library/255xet9e.aspx

    Page.ClientScript.IsClientScriptIncludeRegistered("jQuery");
    

    你可能应该定义一些常量。

    【讨论】:

    • 重要的是要注意,如果通过Page.ClientScript 添加 jQuery,这将有效。如果 jQuery 是在纯 HTML 中添加的,则此方法将不起作用,并将导致页面加载两个 jQuery 实例。
    • 如果我在纯 HTML 中添加 jQuery,我该怎么做?
    • 你不能,如果你在响应中开始钓鱼,你可以,你不想去那里。 ClientScriptManager 旨在跟踪客户端脚本。
    猜你喜欢
    • 2010-09-28
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2013-02-17
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    相关资源
    最近更新 更多