尝试创建CSS下拉菜单时,未定义接收'$'

时间:2014-03-18 17:15:01

标签: jquery html css dynamics-crm-2011

我正在尝试使用一些CSS和JavaScript在HTML页面上创建一个下拉菜单。 CSS似乎工作正常,但JS返回'$' is undefined。我不确定我在这里做错了什么。在CRM 2011功能区中单击按钮时,我将此设置为打开网页。目前它的设置只是在本地运行。

HTML:

<html>
<header>
<link rel="stylesheet" type="text/css" href="OpportunityStyleSheet.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="createRecord.js"></script>  
</header>

<body>
    <h3>Select your Products</h3>

    <div id='cssmenu'>
<ul>
   <li class='active'><a href='index.html'><span>Home</span></a></li>
   <li class='has-sub'><a href='#'><span>Products</span></a>
      <ul>
         <li class='has-sub'><a href='#'><span>Product 1</span></a>
            <ul>
               <li><a href='#'><span>Sub Item</span></a></li>
               <li class='last'><a href='#'><span>Sub Item</span></a></li>
            </ul>
         </li>
         <li class='has-sub'><a href='#'><span>Product 2</span></a>
            <ul>
               <li><a href='#'><span>Sub Item</span></a></li>
               <li class='last'><a href='#'><span>Sub Item</span></a></li>
            </ul>
         </li>
      </ul>
   </li>
   <li><a href='#'><span>About</span></a></li>
   <li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
</body>
</html>

JS:

$('#cssmenu li.has-sub>a').on('click', function(){
        $(this).removeAttr('href');
        var element = $(this).parent('li');
        if (element.hasClass('open')) {
            element.removeClass('open');
            element.find('li').removeClass('open');
            element.find('ul').slideUp();
        }
        else {
            element.addClass('open');
            element.children('ul').slideDown();
            element.siblings('li').children('ul').slideUp();
            element.siblings('li').removeClass('open');
            element.siblings('li').find('li').removeClass('open');
            element.siblings('li').find('ul').slideUp();
        }
    });

function createRecord() {
alert("Button Pressed");
}

createRecord()功能确实有效并显示正确的警报。谢谢你的帮助!

错误消息。 Microsoft Dynamics CRM错误报告内容

<CrmScriptErrorReport>
  <ReportVersion>1.0</ReportVersion>
  <ScriptErrorDetails>
   <Message>'$' is undefined</Message>
   <Line>6</Line>
   <URL>/_common/global.ashx?ver=66087337</URL>
   <PageURL>/userdefined/edit.aspx?etc=3&id=%7b515C22D0-7524-E311-8980-12A32B1E376A%7d&pagemode=iframe&preloadcache=1395165209284</PageURL>
   <Function>anonymous(container,scriptContent,id){if(IsNull(container))container=this.get_headElement();var$v_0=container.ownerDocument.createElement("script");container.appendChild($v_0);!isNullOrEmptyString(id)&&$v_0.setAttribute("id",id);$v_0.setAttribute("type","</Function>
   <CallStack>
    <Function>anonymous(container,scriptContent,id){if(IsNull(container))container=this.get_headElement();var$v_0=container.ownerDocument.createElement("script");container.appendChild($v_0);!isNullOrEmptyString(id)&&$v_0.setAttribute("id",id);$v_0.setAttribute("type","text/javascript");$v_0.text=scriptContent}</Function>
    <Function>anonymous(container,scriptFile){var$v_0=scriptFile.toString();if(this.$4W_1($v_0))return;var$v_1=this.fetchExternalFile($v_0);this.addIncludeInline(container,$v_1,$v_0)}</Function>
    <Function>anonymous(uri,useInlineScripts,scriptLoaded){if(uri.get_path().toUpperCase()==="/_STATIC/_COMMON/SCRIPTS/GLOBAL.JS")uri=Mscrm.CrmUri.create("/_common/global.ashx");if(useInlineScripts)Mscrm.CrmHeader.get_scriptLoader().addIncludeExternalSync(null,uri);elseMscrm.CrmHeader.get_scriptLoader().addIncludeExternalCallback(null,uri,scriptLoaded)}</Function>
    <Function>loadWebResourceScript(sScriptSrc,sId)</Function>
    <Function>LoadJsScripts()</Function>
    <Function>executeAction(action)</Function>
    <Function>anonymous(){executeAction(action);executeActionQueue()}</Function>
   </CallStack>
  </ScriptErrorDetails>
  <ClientInformation>
   <BrowserUserAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BRI/2; BOIE9;ENUS)</BrowserUserAgent>
   <BrowserLanguage>en-us</BrowserLanguage>
   <SystemLanguage>en-us</SystemLanguage>
   <UserLanguage>en-us</UserLanguage>
   <ScreenResolution>1600x900</ScreenResolution>
   <ClientName>Outlook Laptop - Online</ClientName>
   <ClientTime>2014-03-18T11:53:30</ClientTime>
  </ClientInformation>
  <ServerInformation>
    <OrgLanguage>1033</OrgLanguage>
    <OrgCulture>1033</OrgCulture>
    <UserLanguage>1033</UserLanguage>
    <UserCulture>1033</UserCulture>
    <OrgID>{AACB118A-823E-4A12-BFCD-190E5E9BE731}</OrgID>
    <UserID>{E200F73B-57CC-E111-B35F-12A32B1E376A}</UserID>
    <CRMVersion>5.0.9690.3731</CRMVersion>
  </ServerInformation>
</CrmScriptErrorReport>

<CrmScriptErrorReport>
  <ReportVersion>1.0</ReportVersion>
  <ScriptErrorDetails>
   <Message>'$' is undefined</Message>
   <Line>6</Line>
   <URL>/_common/global.ashx?ver=66087337</URL>
   <PageURL>/userdefined/edit.aspx?etc=3&id=%7b515C22D0-7524-E311-8980-12A32B1E376A%7d&pagemode=iframe&preloadcache=1395165209284</PageURL>
   <Function>anonymous(container,scriptContent,id){if(IsNull(container))container=this.get_headElement();var$v_0=container.ownerDocument.createElement("script");container.appendChild($v_0);!isNullOrEmptyString(id)&&$v_0.setAttribute("id",id);$v_0.setAttribute("type","</Function>
   <CallStack>
    <Function>anonymous(container,scriptContent,id){if(IsNull(container))container=this.get_headElement();var$v_0=container.ownerDocument.createElement("script");container.appendChild($v_0);!isNullOrEmptyString(id)&&$v_0.setAttribute("id",id);$v_0.setAttribute("type","text/javascript");$v_0.text=scriptContent}</Function>
    <Function>anonymous(container,scriptFile){var$v_0=scriptFile.toString();if(this.$4W_1($v_0))return;var$v_1=this.fetchExternalFile($v_0);this.addIncludeInline(container,$v_1,$v_0)}</Function>
    <Function>anonymous(uri,useInlineScripts,scriptLoaded){if(uri.get_path().toUpperCase()==="/_STATIC/_COMMON/SCRIPTS/GLOBAL.JS")uri=Mscrm.CrmUri.create("/_common/global.ashx");if(useInlineScripts)Mscrm.CrmHeader.get_scriptLoader().addIncludeExternalSync(null,uri);elseMscrm.CrmHeader.get_scriptLoader().addIncludeExternalCallback(null,uri,scriptLoaded)}</Function>
    <Function>anonymous($p0,$p1,$p2,$p3){Mscrm.CrmHeader.setScriptFile(Mscrm.CrmUri.create($p1),true);for(var$v_0=window,$v_1=$p0.split("."),$v_2=0;$v_2<$v_1.length;$v_2++)if($v_0)$v_0=$v_0[$v_1[$v_2]];if(!IsNull($v_0)&&typeof$v_0===Mscrm.TypeNames.functionType){var$v_3=this.$CN_1($p2,$p3);return$v_0.apply(null,$v_3)}returnnull}</Function>
    <Function>anonymous($p0,$p1,$p2,$p3){var$v_0=this.getCommandDefinition($p0,$p1);if(IsNull($v_0)||IsNull($v_0.Actions))returnfalse;for(var$v_1=0;$v_1<$v_0.Actions.length;$v_1++){var$v_2=$v_0.Actions[$v_1];switch($v_2.ActionType){case2:this.$DF_1($v_2.Attributes);break;case3:var$v_3=$v_2.Attributes;this.$9z_1($v_3.FunctionName,$v_3.Library,$v_2.Parameters,$p2);break;case1:this.$DG_1($v_2.Attributes,$v_2.Parameters);break}}returntrue}</Function>
    <Function>anonymous($p0,$p1,$p2){var$v_0=this.parseCommandFromRibbon($p0),$v_1=this.$7w_1($v_0.command,$v_0.entityLogicalName,$p1,$p2),$v_2=$p1;if(!IsNull($v_2)&&!isNullOrEmptyString($v_2.PopulationXML)&&!$v_2.SuppressCommandIncludes){var$v_3=null;if($v_0.entityContext==="Form"){var$v_4=$find("crmFormSelector");if($v_4)$v_3=$v_4.get_currentFormId()}$v_2.PopulationXML=this.$Ep_1($v_2.PopulationXML,$v_0.entityLogicalName,$v_3)}return$v_1}</Function>
    <Function>anonymous($p0,$p1,$p2){if(this.$1w_1&&!this.$1w_1.$3m_1)returnthis.$1w_1.handleCommand($p0,$p1,$p2);returnfalse}</Function>
    <Function>anonymous(handler,commandId,properties,sequenceNumber){returnhandler.handleCommand(commandId,properties,sequenceNumber)}</Function>
    <Function>anonymous($p0,$p1,$p2){var$v_0=this.$2S_0[$p0];if(CUI.ScriptUtility.isNullOrUndefined($v_0))returnfalse;elseif(Array.isInstanceOfType($v_0)){for(var$v_1=$v_0,$v_2=false,$v_3=0;$v_3<$v_1.length;$v_3++){var$v_4=$v_1[$v_3];if(this.callCommandHandler($v_4,$p0,$p1,$p2))$v_2=true}return$v_2}elsereturnthis.callCommandHandler($v_0,$p0,$p1,$p2)}</Function>
    <Function>anonymous(commandId,properties){returnthis.$DE_0(commandId,properties,this.getNextSequenceNumber())}</Function>
    <Function>anonymous(commandId,properties,commandInfo,root){returnthis.$10_1.executeCommand(commandId,properties)}</Function>
    <Function>anonymous($p0){if(CUI.ScriptUtility.isNullOrUndefined($p0.$4_1))return;$p0.$7U_1=this.$DU_1();var$v_0=$p0.get_commandInfo();$v_0.CommandId=$p0.$4_1;$v_0.RootId=this.$4_0;$v_0.RootType=this.get_rootType();!CUI.ScriptUtility.isNullOrUndefined(this.$26_1)&&this.$26_1.executeRootCommand($p0.$4_1,$p0.$34_1,$v_0,this)}</Function>
    <Function>anonymous($p0){this.$7w_1($p0);returntrue}</Function>
    <Function>anonymous($p0){if($p0.$I_1!==11){$p0.get_commandInfo().RootLocation=$p0.$I_1===2?"UpperRibbon":"LowerRibbon";if($p0.$I_1===2){var$v_0=$p0.$34_1;$p0.get_commandInfo().TabId=$v_0.NewContextId}}returnCUI.Root.prototype.$2p_0.call(this,$p0)}</Function>
    <Function>anonymous($p0){this.$2p_0($p0)&&!CUI.ScriptUtility.isNullOrUndefined(this.$M_0)&&this.$M_0.$B0_0($p0);this.$Ao_0($p0)}</Function>
    <Function>anonymous($p0){this.$2p_0($p0)&&!CUI.ScriptUtility.isNullOrUndefined(this.$M_0)&&this.$M_0.$B0_0($p0);this.$Ao_0($p0)}</Function>
    <Function>anonymous($p0){this.$2p_0($p0)&&!CUI.ScriptUtility.isNullOrUndefined(this.$M_0)&&this.$M_0.$B0_0($p0);this.$Ao_0($p0)}</Function>
    <Function>anonymous($p0){this.$2p_0($p0)&&!CUI.ScriptUtility.isNullOrUndefined(this.$M_0)&&this.$M_0.$B0_0($p0);this.$Ao_0($p0)}</Function>
    <Function>anonymous($p0){this.$2p_0($p0)&&!CUI.ScriptUtility.isNullOrUndefined(this.$M_0)&&this.$M_0.$B0_0($p0);this.$Ao_0($p0)}</Function>
    <Function>anonymous($p0){this.$2p_0($p0)&&!CUI.ScriptUtility.isNullOrUndefined(this.$M_0)&&this.$M_0.$B0_0($p0);this.$Ao_0($p0)}</Function>
   </CallStack>
  </ScriptErrorDetails>
  <ClientInformation>
   <BrowserUserAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BRI/2; BOIE9;ENUS)</BrowserUserAgent>
   <BrowserLanguage>en-us</BrowserLanguage>
   <SystemLanguage>en-us</SystemLanguage>
   <UserLanguage>en-us</UserLanguage>
   <ScreenResolution>1600x900</ScreenResolution>
   <ClientName>Outlook Laptop - Online</ClientName>
   <ClientTime>2014-03-18T11:53:33</ClientTime>
  </ClientInformation>
  <ServerInformation>
    <OrgLanguage>1033</OrgLanguage>
    <OrgCulture>1033</OrgCulture>
    <UserLanguage>1033</UserLanguage>
    <UserCulture>1033</UserCulture>
    <OrgID>{AACB118A-823E-4A12-BFCD-190E5E9BE731}</OrgID>
    <UserID>{E200F73B-57CC-E111-B35F-12A32B1E376A}</UserID>
    <CRMVersion>5.0.9690.3731</CRMVersion>
  </ServerInformation>
</CrmScriptErrorReport>

2 个答案:

答案 0 :(得分:0)

看起来你没有加载正确的JQuery库。请为我们提供完整的主管部分。

请看一下这个主题:JavaScript runtime error: '$' is undefined以解决类似的问题。

添加了: 我现在可以看到头部 - &#34; // ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"不是正确的库URL - 添加http:到它。

答案 1 :(得分:0)

我能够解决这个问题。 jscript库基本上需要调用两次。一旦进入html文件(就像你上面提到的那样),再次在CRM实体上运行该函数。我不认为这需要发生,因为在点击按钮调用显示网页的功能之前没有被调用。但是,显然我错了。

感谢大家的帮助和评论。