Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击另一个div时显示div_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 单击另一个div时显示div

Javascript 单击另一个div时显示div,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我添加了三张图片。请看它们。 创建这样的东西的最佳解决方案是什么?我会在每一行之后创建一个大容器,这个容器被折叠。单击3个覆盖容器中的一个后,我会用文本填充容器并显示它。但是,当显示器不能连续显示3个div时会发生什么情况,因为我将使用flex-box?用更少的jquery有更好的解决方案吗?也许这是一个很好的起点: HTML CSS 您可以使用javascript来解决这个问题,比如。。。。 html代码: <div id="a"> <a href="#e" onc

我添加了三张图片。请看它们。


创建这样的东西的最佳解决方案是什么?我会在每一行之后创建一个大容器,这个容器被折叠。单击3个覆盖容器中的一个后,我会用文本填充容器并显示它。但是,当显示器不能连续显示3个div时会发生什么情况,因为我将使用flex-box?用更少的jquery有更好的解决方案吗?

也许这是一个很好的起点:

HTML

CSS


您可以使用javascript来解决这个问题,比如。。。。 html代码:

<div id="a"> 
  <a href="#e" onclick="goB()"><h3>wellcome</h3></a>

</div>
<div id="b">
  <a href = "#er" onclick="goA"> <h3>hello...</h3> </a>
</div>

添加一个div并将其显示设置为隐藏。 获取特定div的onclick事件,并将display属性设置为block

window.addEventListener(“加载”,函数(){
document.getElementById(“单击”).onclick=function(){
document.getElementById(“div-1”).style.display=“block”;
};
});
.row
{
宽度:100%;
}
.三分之一
{  
宽度:33.33333%;
浮动:左;
填充:30px0;
}
.全宽
{
显示:无;
宽度:100%;
文本对齐:居中;
}

第1列单击“我”
第2栏
第3栏
全宽Div
第1栏
第2栏
第3栏

最佳解决方案:花时间试验
CSS
或者做一些研究。
document.querySelectorAll('.row').forEach((element, index) => {
  element.style.order = index * 2;
});

document.querySelectorAll('.element').forEach(element => {
  element.addEventListener('click', event => {
    var newRow = document.createElement('div');
    newRow.classList.add('row');
    newRow.style.order = +event.currentTarget.parentNode.style.order + 1;
    var newElement = document.createElement('div');
    newElement.classList.add('element');
    newRow.appendChild(newElement);
    event.currentTarget.parentNode.parentNode.appendChild(newRow);
  });
});
.element {
  min-width: 100px;
  height: 50px;
  flex: 1;
  border: 1px solid black;
  flex-wrap: nowrap;
}

.row {
  width: 350px;
  display: flex;
  flex-direction: row;
}

.wrapper {
  display: flex;
  flex-direction: column;
}
<div id="a"> 
  <a href="#e" onclick="goB()"><h3>wellcome</h3></a>

</div>
<div id="b">
  <a href = "#er" onclick="goA"> <h3>hello...</h3> </a>
</div>
function goB()
{
  document.getElementById("a").style.display="none";
  document.getElementById("b").style.display="block";
}
function 
{
  document.getElementById("b").style.display="none";
  document.getElementById("a").style.display="block";
}