【发布时间】:2016-09-02 09:05:25
【问题描述】:
我的页面上有 2 个 div,如果禁用了 javascript,则应显示一个,如果未禁用 javascript,则应显示另一个。
我的问题是:即使没有禁用 javascript,也会短暂显示包含禁用 javascript 消息的 div,并且 它在页面加载后几秒钟后隐藏。
这是我拥有的 html(简化版):
<html>
<head>
<body>
<!-- This div is displayed only if the JavaScript is DISABLED -->
<div class="wrapper-page" id="no-js">
<p class="text-muted m-b-0 font-13 m-t-20" style="color:red !important;font-weight: bold;">
JavaScript has been disabled message.....
</p>
</div>
<!-- end no-js div -->
<!-- This div is hidden by default, and is displayed only if the JavaScript is ENABLED -->
<div class="wrapper-page" id="wrapper-page" style="display:none;">
<p>My regular content goes here...</p>
</div>
<!-- end wrapper page -->
<script src="<?php echo base_url(); ?>backOffice/assets/js/jquery.min.js"></script>
<!-- If JavaScrpt is disabled, then the main div remain not visible and only the div with the
Disabled JavaScript error message is displayed. -->
<script src="<?php echo base_url(); ?>backOffice/assets/js/disabledjs.js"></script>
</body>
</html>
这是 JavaScript 文件的内容:
$(document).ready(function () {
$("#no-js").hide();
$("#no-js").css('visibility','hidden');
$("#no-js").css('display','none');
$("#wrapper-page").css("display", "block");
});
我尝试将 JS 和 jQuery 移到顶部,我尝试切换 html div 的顺序,到目前为止没有任何帮助。
【问题讨论】:
-
放置javascript代码 $("#no-js").hide();在最后一行并且没有 document.ready 并尝试一次..
-
@SandeepJPatel 不,不要工作。
标签: javascript jquery html css