以下代码位于我的网页的主题部分。它引用的标记的HTML(#dmsmenu和#dmssubmenu)位于外部文件中,该文件在页面加载时动态加载。问题出在IE8上(一切都在Chrome和Safari中运行正常)。当页面加载时,它将进入函数,但不执行其中包含的代码。代码更改主菜单栏的背景颜色和文本颜色,并应显示子菜单。任何帮助将不胜感激。
$(window).load(function() {
$("#dmsmenu").css('background', '#FFFFFF');
$("#dmsmenu").css('color', '#DF7401');
$("#dmssubmenu").appendTo('#dmssubmenu');
$("#dmssubmenu").show();
});
HTML
<tr>
<td align="center" valign="middle">
<div id="menubar_index">
<!--menubar contents are loaded dynamically-->
</div>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<div id="menubar_sub">
<!--menubar contents are loaded dynamically-->
</div>
</td>
</tr>
Ext HTML menubar_index div
<div class="topgradientblueline">
<div id="wrapper">
<div id="menuspacer">
</div>
<div id="dmsmenu" style="font-family:Sans-Serif; font-size:small; text- decoration:none ">
<a href="document_management_solutions.html">Document Management Solutions</a>
</div>
<div id="lsTMFmenu" style="font-family:Sans-Serif; font-size:small; ">
<a href="TMF_solutions.html">Life Science TMF Solutions</a>
</div>
<div id="lssampmenu" style="font-family:Sans-Serif; font-size:small; ">
<a href="lss_solutions.html">Life Science Sampling Solutions</a>
</div>
<div id="drsmenu" style="font-family:Sans-Serif; font-size:small; ">
<a href="about_drs.html">About DRS</a>
</div>
</div>
</div>
Ext HTML menubar_sub div
<div style="height:50px; width:950px;">
<div id="dmssubmenu" style="display: none">
<span class="menu2ndlevel"><a id="dmprofsvc" href="" style="text-decoration:none">Professional Services</a></span>
<span class="menu2ndlevelorangeline">|</span>
<span class="menu2ndlevel"><a id="dmdocimgproc" href="#" style="text-decoration:none">Document/Image Processing</a></span>
<span class="menu2ndlevelorangeline">|</span>
<span class="menu2ndlevel"><a id="dmworkflow" href="#" style="text-decoration:none">Workflow</a></span>
<span class="menu2ndlevelorangeline">|</span>
<span class="menu2ndlevel"><a id="dmsoftware" href="#" style="text-decoration:none">Software Solutions</a></span>
<span class="menu2ndlevelorangeline">|</span>
<span class="menu2ndlevel"><a id="dmdocretieval" href="#" style="text-decoration:none">Document Retrieval</a></span>
</div>
</div>
答案 0 :(得分:1)
即可能需要更长时间来加载整个页面...尝试等待一段时间,或者更常用的做法是使用
$(document).ready(function(){ ... });
因为这将在HTML DOM准备好使用时执行。访问。
每个SpYk3HH
建议的另一个选项是
$(function() { ... });
jQuery - What are differences between $(document).ready and $(window).load?