简体   繁体   English

链接打开div(手风琴样式)

[英]a link open div (accordion style)

I just need div.accordion1 to be opened when I click on a#accordion1 . 我只需要在单击#accordion1时打开div.accordion1即可。 Im not an expert on Javascript. 我不是Java专家。 I have /wp-includes/js/jquery/jquery.js?ver=1.12.4 loading on the page trying to use the simple html layout below: 我在页面上加载了/wp-includes/js/jquery/jquery.js?ver=1.12.4,试图使用以下简单的html布局:

in the header section: 在标题部分:

<div class="header">
    <a href="#accordion1">toggle open / close accordion1</a>
    <a href="#accordion2">toggle open / close accordion2</a>
</div>

positioned somewhere in the body of page: 位于页面正文中的某个位置:

<div class="body">

    <div class="accordion1">
        Lorem Ipsum....
    </div>

    <div class="accordion2">
        Lorem Ipsum....
    </div>

</div>

if i understand right, you want when you press the toggle button, to show a paragraph, and when you click the same button to hide the specific paragraph 如果我理解正确,则希望在按下切换按钮时显示一个段落,并在单击相同按钮时隐藏特定段落

here is a good example from w3-schools https:// www.w3schools.com/howto/howto_js_toggle_hide_show.asp 这是来自w3-schools的一个很好的例子https:// www.w3schools.com/howto/howto_js_toggle_hide_show.asp

you have to make a button that calls a function on click 您必须创建一个在单击时调用函数的按钮

<button onclick="myFunction()">Try it</button>

<div id="myDIV">
This is my DIV element.
</div>


<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
    x.style.display = "block";
} else {
    x.style.display = "none";
}
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM