gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:46:19 27 4
gpt4 key购买 nike

我正在尝试使用一些 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>

最佳答案

我认为您只需要在本地运行时附加 http:,稍后可以将其删除,因为“//”将作为协议(protocol)前缀。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

PS:在每个文档中提到 head、meta、title 标签总是好的。与上述问题无关。这是干净和正确的写作方式。 :)

您的 html 文档...根据要求:

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

</head>

<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>
<script type="text/javascript">
$('#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");
}
</script>
</body>
</html>

干杯,

阿肖克

关于jquery - 尝试创建 CSS 下拉菜单时未定义接收 '$',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22486411/

27 4 0