<div id="abc" style="display: none;"><h1>abc</h1></div>
こんにちは!私はdivを隠しますが、私はそれを入力するときに見たいです#abc私はこのテキストを見ることができません。DIVについて(Java非表示と非表示)
<div id="abc" style="display: none;"><h1>abc</h1></div>
こんにちは!私はdivを隠しますが、私はそれを入力するときに見たいです#abc私はこのテキストを見ることができません。DIVについて(Java非表示と非表示)
あなたの要件ごとにサンプルの下に見つけてください。
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
if(window.location.href.indexOf("#abc")!=-1)
{
//alert("Page is loaded");
document.getElementById("abc").style.display="block";
}
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
<div id="abc" style="display: none;"><h1>abc</h1></div>
</body>
</html>
これはjqueryのを使用してそれを行うことができる方法である。
var url = "https://abcdefgh.carrd.co/#abc";
var hash = url.substring(url.indexOf("#"));
// You can use
// var hash = window.location.hash;
// but i need to write the url to show you that is working.
if ($(hash).length) { //check if div exists
$(hash).show();
}
#abc, #cde
{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc">ABC</div>
<div id="cde">CDE</div>
人々はJavaScriptに頼ることなく、それをしたい場合は、CSSのソリューションは、コメントで述べたように、:target
疑似クラスを使用することです。
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<style>
#abc {display:none}
#abc:target {display:block}
</style>
</head>
<body>
<div id="abc"><h1>abc</h1></div>
</body>
</html>
:
if(window.location.href.indexOf("#abc")!=-1) {
document.getElementById("abc").style.display="block";
}}
あなたは#abcタイプ?表示されているdivを表示するには、javascriptが必要です。 cssとhtmlだけで「何か」が起きた後にdivを表示することはできません。 –
アドレスバー。クロム。アドレスの終わり。 –
これで、そのIDをURLに追加してdivを表示させようとしていますか?その場合、 ':target'を参照してください。 –