試圖通過單擊按鈕來打開和關閉div顯示。下面的相關代碼。.toggle()未在按鈕單擊上註冊
HTML
<li>
<a id="academic_link" href="#">
<button id="academic_button">Academic</button>
</a>
</li>
<div id="legend_content">
<div id="academic_content">
CSS
#legend_content {
display: none;
position: relative;
padding: 25px 10px 25px 10px;
text-align: center;
}
#academic_button {
background-color: black; /* Test colors later -- Green - #4CAF50 */
border-width: 1px;
border-bottom: none;
color: white;
border-color: black;
padding: 10px 2px;
text-align: center;
text-decoration: none;
display: inline;
font-size: 11.5px;
border-top-left-radius: 0px;
font-weight: bold;
width: 78px;
}
JQuery的
$(document).ready(function() {
$("#academic_button").click(function() {
$("legend_content").toggle();
});
});
我覺得像點擊甚至沒有得到註冊。
忘了'#'。這樣寫:'$(「#legend_content」)。toggle();' – Banzay
'$(「legend_content」)。toggle();'應該是'$(「#legend_content」)toggle();' – abc123
@ Taplar,thnx。固定它 – Banzay