我不知道從哪裏開始以及要搜索什麼。我在我的HTML文件中有兩個鏈接。當點擊上面的鏈接並點擊第二個鏈接時,我希望頁面內的一個框出現在鏈接下方,第一個框會消失,第二個鏈接下面的另一個框將會出現。就像鏈接被點擊時的滑動框一樣。這是什麼代碼/職位?非常感謝!在頁面內打開一個框
-1
A
回答
0
我不瞭解你,但我猜你想一些事情是這樣的:
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
#myDIV {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: lightblue;
margin-top:20px;
}
<p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
This is my DIV element.
</div>
+0
是的,這是我正在尋找的! :)我會從這開始。非常感謝! –
1
可以被稱爲內容切換器或標籤控件。以下是在CSS中執行此操作的簡單方法。
.box {
display: none;
}
.box:target {
display: block;
}
<a href="#one">one</a> <a href="#two">two</a>
<div id="one" class="box">box one</div>
<div id="two" class="box">box two</div>
而這裏的一個辦法做到這一點的JS
var links = document.getElementsByTagName('a'),
boxes = document.getElementsByClassName('box');
for (var i = 0; i < links.length; i++) {
links[i].addEventListener('click',function(e) {
e.preventDefault();
var url = this.getAttribute('href').replace('#','');
for (var j = 0; j < boxes.length; j++) {
boxes[j].classList.remove('active');
}
document.getElementById(url).classList.add('active');
})
}
.box {
display: none;
}
.active {
display: block;
}
<a href="#one">one</a> <a href="#two">two</a>
<div id="one" class="box">box one</div>
<div id="two" class="box">box two</div>
+0
謝謝!這是我正在尋找的。我將從此開始。 :) –
+0
@AllenDelaCruz np!我也用一個簡單的JS解決方案更新了我的答案。 –
相關問題
- 1. 在整個頁面而不是在一個框架內打開一個鏈接
- 2. 如何在另一個框架中打開一個頁面
- 3. 打開一個新頁面?
- 4. 使用Twitter Bootstrap在一個頁面內打開多個模式對話框
- 5. 在一個頁面上打開多個模式框
- 6. 在HTML中打開另一個頁面
- 7. 如何在同一頁面中打開多個jquery對話框
- 8. 如何在GWT中打開一個新頁面(內部鏈接)?
- 9. 如何從另一個angularjs頁面打開一個angularjs頁面
- 10. 在頁面打開填充文本框
- 11. 在模式框中打開頁面
- 12. 在fancybox內打開html頁面
- 13. 打開一個對話框autocloses面板
- 14. Codeigniter:用jQuery打開另一個頁面
- 15. 如何讓php打開一個頁面?
- 16. 從ajax打開一個HTML頁面
- 17. 確定Postback打開一個新頁面
- 18. 從一個PHP頁面打開MS Word
- 19. jQuery Tabs - 從另一個頁面打開
- 20. 當從另一個頁面加載內容時,jquery對話框不會打開第二個頁面
- 21. JSF重定向到另一個頁面並打開對話框
- 22. 打開一個jQuery UI的對話框頁面滾動起來
- 23. jQuery的對話框中打開另一個頁面
- 24. 設置一個鏈接打開一個頁面並打開一個Javascript表單?
- 25. 在另一個頁面上打開一個頁面引導程序jQuery
- 26. Jquery - 用當前頁面的內容打開一個新窗口
- 27. 無法打開模式內的鏈接的另一個頁面
- 28. 在當前WebView頁面內打開的頁面
- 29. 如何打開一個頁面,點擊模式按鈕打開
- 30. 在另一個選項卡中打開一個aspx頁面
提供您的HTML代碼。 –
嗨!我開始我的代碼,我不知道從哪裏開始,因爲我無法在Google上找到這個「正確的可搜索教程」。 –