導航:首頁 > 編程語言 > js層顯示和隱藏

js層顯示和隱藏

發布時間:2023-02-13 09:50:26

1. javaScript怎麼實現層的顯示和隱藏

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=ansi" />
<title>Jay Skript And The Domsters: About the band</title>
<style type="text/css">
.section{width:560px;border:black solid 1px;}
#jay{background-color:#ccc;}
#domsters{background-color:#eee;}
</style>
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function showSection(id) {
var divs = document.getElementsByTagName("div");
for (var i=0; i<divs.length; i++ ) {
if (divs[i].className.indexOf("section") == -1) continue;
if (divs[i].getAttribute("id") != id) {
divs[i].style.display = "none";
} else {
divs[i].style.display = "block";
}
}
}

function prepareInternalnav() {
if (!document.getElementsByTagName) return false;
if (!document.getElementById) return false;
if (!document.getElementById("internalnav")) return false;
var nav = document.getElementById("internalnav");
var links = nav.getElementsByTagName("a");
for (var i=0; i<links.length; i++ ) {
var sectionId = links[i].getAttribute("href").split("#")[1];
if (!document.getElementById(sectionId)) continue;
document.getElementById(sectionId).style.display = "none";
links[i].destination = sectionId;
links[i].onclick = function() {
showSection(this.destination);
return false;
}
}
}

addLoadEvent(prepareInternalnav);
</script>
</head>
<body>
<div id="content">
<h1>About the band</h1>
<ul id="internalnav">
<li><a href="#jay">第一段</a></li>
<li><a href="#domsters">第二段</a></li>
</ul>
<div class="section" id="jay">
<h2>第一段</h2>
<p>Jay Skript is going to rock your world!</p>
<p>Together with his compatriots The Domsters, Jay is set for world domination. Just you wait and see.</p>
<p>Jay Skript has been on the scene since the mid nineties. His talent hasn't always been recognized or fully appreciated. In the early days, he was often unfavorably compared to bigger, similarly-named artists. That's all in the past now.</p>
</div>
<div class="section" id="domsters">
<h2>第二段</h2>
<p>The Domsters have been around, in one form or another, for almost as long. It's only in the past few years that The Domsters have settled down to their current, stable line-up. Now they're a rock-solid bunch: methodical and dependable.</p>
</div>
</div>
</body>
</html>

2. 用js控制div層的顯隱和移動

JS控制DIV層顯示與隱藏
用JS控制DIV層的隱藏與顯示。頁面中有三個DIV層,三個超級鏈接,實現的功能是點擊一個鏈接,顯示相應的DIV層,同時隱藏另外兩個DIV層。
實例代碼如下:
示例一
<html>
<head>
<script type="text/javascript">
function changeBody(index){
switch(index){
case 1:{
document.getElementById('iDBody1').style.display = "";
document.getElementById('iDBody2').style.display = "none";
document.getElementById('iDBody3').style.display = "none";
break;
}
case 2:{
document.getElementById('iDBody1').style.display = "none";
document.getElementById('iDBody2').style.display = "";
document.getElementById('iDBody3').style.display = "none";
break;
}
case 3:{
document.getElementById('iDBody1').style.display = "none";
document.getElementById('iDBody2').style.display = "none";
document.getElementById('iDBody3').style.display = "";
break;
}
}
}
</script>
</head>
<body>
<a href="javascript:changeBody(1)">模塊A</a>
<a href="javascript:changeBody(2)">模塊B</a>
<a href="javascript:changeBody(3)">模塊C</a>
<div style="display: none" id="iDBody1"> 模塊(一)的相關內容 </div>
<div style="display: none" id="iDBody2"> 模塊(二)的相關內容 </div>
<div style="display: none" id="iDBody3"> 模塊(三)的相關內容 </div>
</body>
</html>

示例二
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>DIV-3</title>
<style type="text/css">
.hiddiv {display:none}
</style>
<SCRIPT language=JavaScript>
<!-- function a(x){
for( i=0; i<divLen; i++ ){
if(allDiv[i].className=="hiddiv")
allDiv[i].style.display = "none"
if(allDiv[i].id=="div"+x)
allDiv[i].style.display = "block"
}
}
window.onload = function(){
allDiv = document.getElementsByTagName("div");
divLen = allDiv.length
}
-->
</SCRIPT>
</head>
<body>
<div id="div1" class="hiddiv" style="display:block">此處顯示 id "div1" 的內容</div><br>
<div id="div2" class="hiddiv">此處顯示 id "div2" 的內容</div><br>
<div id="div3" class="hiddiv">此處顯示 id "div3" 的內容</div><br>
<div id="div4" class="hiddiv">此處顯示 id "div4" 的內容</div><br>
<select onChange="a(value)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</body>
</html>

3. js控制div的顯示和隱藏

使用JavaScript控制div的顯示隱藏,通常是修改div元素的display為none。


display屬性 定義和用法

display 屬性規定元素應該生成的框的類型。

display屬性 可能的值

document.getElementById("div1").style.display="block";

其他方式

除了修改display,還可以通過修改元素的寬度和高度為零實現隱藏效果。

4. 前端使用JS和JQuery顯示隱藏標簽

一.使用JQuery使用

二.jquery判斷元素是否隱藏

三.使用JS隱藏和顯示
a.隱藏後釋放佔用的頁面空間
通過設置display屬性可以使div隱藏後釋放佔用的頁面空間.
style="display: none;"

b.隱藏後仍佔有頁面空間,顯示空白
div的visibility可以控制div的顯示和隱藏,但是隱藏後頁面顯示空白.
style="visibility: none;"

5. 怎麼用js顯示隱藏div

怎麼用js來顯示或隱藏一個div?很簡單,下面一起來看一下。

6. JS控制層的顯示隱藏 .NET

點擊某個button時,調用show(i),把id為"div"+i的那一層的display設為block(簡單點說就是,如果你點了第一個button,就顯示id為「div1」的層), 然後再看看那個hidden1是否已經賦值了,如果有值而且這個值不等於你剛顯示的那個層的id的話,就把id等於這個值的那個層(也就是上一次點擊的那個層)隱藏起來。 上面這些事做完了,就把當前顯示的那個層的div的id賦值給那個hidden1,供下次點擊的時候隱藏。 基本上控制層顯示隱藏的思路都差不多的,學js的話,投入到jquery的懷抱吧,很火的

求採納

7. JS點擊按鈕顯示隱藏層問題

if(obj!=document.getElementById("divOne_1"))
{
document.getElementById("divOne_1").style.display="none";
}
最傻瓜的方式,在
click_a
函數內增加一個判斷,如果obj不是divOne_1的話,則對obj則將divOne_1進行隱藏。

8. js怎麼控制a標簽的顯示和隱藏

將標簽放在層裡面,控制層的顯示和隱藏就可以:
show是層的專id名,
隱藏層:屬document.getelementbyid("show").style.display
=
"none";
顯示層:document.getelementbyid("show").style.display
=
"block";

9. 在js文件里怎樣寫層的顯示和隱藏了

document.getElementById(id).style.display
"" 則顯示
"none" 隱藏

或者jquery
$('#id').hide(); 隱藏
$('#id').show(); 顯示

10. 用JS怎麼控制層的顯示和隱藏

主要是應用CSS的z-index來控制,通過改變層的z-index的值大小來讓層成為當前獲得焦點。而如果是要隱藏,則改變層的display就行了。

閱讀全文

與js層顯示和隱藏相關的資料

熱點內容
奧維使用教程 瀏覽:324
編程程序怎麼轉到plc上 瀏覽:807
文件名沖突但是找不到 瀏覽:261
上海瑞金醫院app下載 瀏覽:998
qq群里的機器人買武器 瀏覽:428
捕魚達人歷史版本 瀏覽:73
mp4視頻文件解密軟體 瀏覽:62
多軸編程哪個軟體最方便 瀏覽:27
老平板哪個是顯示屏數據線插座 瀏覽:849
5sing上傳音頻文件格式 瀏覽:171
win10輸入文件滑鼠右鍵異常 瀏覽:634
聽幼兒故事用什麼app 瀏覽:514
iphone修改音頻文件名 瀏覽:53
國家氣象站點數據在哪裡下載 瀏覽:342
網路設置的網站 瀏覽:914
手機測量放樣怎麼導數據和線型 瀏覽:648
企業展示型網站源碼 瀏覽:781
易花花app哪裡下載 瀏覽:323
外國程序員職業生涯長 瀏覽:709
看理想app怎麼注銷賬號 瀏覽:545

友情鏈接