* * Why does the hidden div not appear after clicking on javascript-, and why does it not automatically close the content above when I click on the content below? **

when you click "Click 1", "Click 2", "Click 3", the hidden div below it appears; in addition, when you click "Click 2", the hidden content under "Click 1" automatically disappears, and so on.
the current problem is that there is no response after clicking, as shown in the figure. What"s wrong with the picture description
code? Can you give me a hint or change?
Thank you!

< hr >

the code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equip="Content-Type" content="text/html" charset="UTF-8"/>
    <title></title>
<style>
 .show    {
    clear:both;
    width:400px;
    height:32px;
    border:1px solid;
    display:none
    }
.block    {
    clear:both;
    width:400px;
    height:58px;
    border:1px solid;
    }
</style>
<script>
function pop(oDiv){
var a=["D1","D2""D3"]

for (var i=0;i<a;iPP;)
{
if(oDiv==a[i]
{
var ob=document.getElementById(a[i]);
ob.style.display="block";
}
else
 {
var ob=document.getElementById(a[i]);
ob.style.display="none"};
}
}
</script>
</head>
<body>

<div ><a href="-sharp" onclick="pop(oDiv)">1</a></div>
<div class="show" id="D1" >555</div>
<div class="block"></div>
<div ><a href="-sharp" onclick="pop(oDiv)">2</a></div>
<div class="show" id="D2" >555</div>
<div class="block"></div>
<div ><a href="-sharp" onclick="pop(oDiv)">3</a></div>
<div class="show" id="D3" >555</div>
<div class="block"></div>

</body>
</html>
May.27,2022

1.

where the array is defined in script is missing a comma
will

var a=['D1','D2''D3']
Change

to

var a=['D1','D2','D3']

2.
multiple semicolons in parentheses of the for loop below

The

if statement is missing parentheses

and the condition of your for loop is not correct either. I should be less than a.length

.

there are many problems with this code, so it is recommended to take a look at it again.


the code you gave has a lot of syntax errors.
https://jsfiddle.net/EverJust...


css
.slide_box {
  width: 400px;
}

html
   <div class="slide_box">
    <a href="-sharp" onclick="pop(this)">1</a>
    <div class="show" id="D1">555</div>
    <div class="block"></div>
  </div>
  ...

js
function pop(btn) { //slide
      var el = ['D1', 'D2', 'D3'], pre = btn.parentNode;
      var ids = pre.children[1].getAttribute('id');
      for (var i = 0, ob; i < el.length; iPP) {
        ob = document.getElementById(el[i]);
        if (ob)
          ob.style.display = (el[i] == ids) ?
            (ob.style.display == 'block' ? 'none' : 'block') :
            'none';
      }
    }

    document.addEventListener('click', function (e) { //
      e = e || window.event || event;
      var src = e.srcElement || e.target,
        res = findCls(src, 'slide_box');
      if (!res)
        hideSty('.slide_box .show');
    });

    function hideSty(cls) { //classstyle none
      cls = typeof cls != 'string' ? cls : document.querySelectorAll(cls);
      for (var i = 0; i < cls.length; iPP) {
        cls[i].style.display = 'none';
      }
    }

    function findCls(el, cls) { //class
      var pre = el.parentNode;
      if (!cls || !el) { return false; }
      if (pre) {
        if (!pre.className) { return false; }
        while (pre.className.indexOf(cls) == -1) {
          pre = pre.parentNode;
          if (!pre.className) { return false; }
          if (pre.className.indexOf(cls) != -1) {
            return true;
          }
        }
        return true;
      }
    }
Menu