简体   繁体   English

禁用JavaScript时使隐藏的div可见

[英]Make a hidden div visible when javascript disabled

I currently have a div in my HTML that is initially hidden (using display:none ). 我目前在我的HTML中有一个div,它最初是隐藏的(使用display:none )。

<div class="fulladdress">
   <p>Only display the contents of this div when an element is clicked!</p>
</div>

I then use the following Javascript so when the .autocompleteitem item is clicked, it displays: 然后,我使用以下Javascript,因此当单击.autocompleteitem项目时,它将显示:

$(document).ready(function() {

    $(document).on('click','.autocompleteitem:not(.autocompleteitemwithcontainer)',function(){
        $("div.fulladdress").show();
    });
});

However , if Javascript is disabled, the full address will never display. 但是 ,如果禁用了Javascript,则将不会显示完整的地址。 How do I resolve this? 我该如何解决?

Maybe try working with the tag <noscript> . 也许尝试使用标记<noscript> It runs the code inside it if the javascript is disabled. 如果禁用了javascript,它将在其中运行代码。

Use following HTML code. 使用以下HTML代码。 Now user can see the div when javaScript disabled by user or device not support javaScript. 现在,当用户或设备禁用的JavaScript不支持javaScript时,用户可以看到div。 You can customize your div by select .fulladdress class on CSS. 您可以通过在CSS上选择.fulladdress类来自定义div。

 <noscript>
     <div class="fulladdress">
        <p>Only display the contents of this div when an element is clicked!
        </p>
     </div>
</noscript>

You can try something like this. 您可以尝试这样。

If javascript enabled - Hide div on document ready and then show on click event 如果启用了JavaScript-准备好在文档上隐藏div,然后在单击事件时显示

If javascript disabled your document ready function wont execute and it wont hide the div 如果javascript禁用了您的文档准备功能将不会执行,并且不会隐藏div

 $(document).ready(function() { $("div.fulladdress").hide(); $("#button").on('click',function(){ $("div.fulladdress").show(); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="fulladdress"> <p>Only display the contents of this div when an element is clicked!</p> </div> <div class="button"> <button id="button">display</button> </div> 

Try this 尝试这个

<noscript>
    <style type="text/css">
        .pagecontainer {display:none;}
    </style>
    <div class="noscriptmsg">
    You don't have javascript enabled.
    </div>
</noscript>

If you absolutely have to have your div hidden at first even with JavaScript disabled and only then revealed, then there are some ways to deal with it. 如果绝对必须在禁用JavaScript的情况下首先隐藏div ,然后才将其显示出来,那么可以使用一些方法来处理它。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM