[英]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
,然后才将其显示出来,那么可以使用一些方法来处理它。
You can detect if JavaScript is disabled and request the user to enable it, and not show the page unless the user does so. 您可以检测是否禁用了JavaScript并请求用户启用它,除非用户这样做,否则不显示页面。 How to detect if JavaScript is disabled?
如何检测是否禁用了JavaScript?
You can use CSS properties to show/hide .fulladdress
on hover instead of on a click (you might want to modify your div
for that, or put it inside a <noscript>
tag). 您可以使用CSS属性在悬停时(而不是单击时)显示/隐藏
.fulladdress
(您可能想要为此修改div
或将其放在<noscript>
标记内)。
You might want to use 'hacks' to detect a click without using JavaScript. 您可能想使用“ hacks”来检测点击,而不使用JavaScript。 Here are a few examples:
这里有一些例子:
Show / hide div on click with CSS 使用CSS单击显示/隐藏div
What is the simplest way to implement pure css show/hide? 实现纯CSS显示/隐藏的最简单方法是什么?
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.