Javascript Style.display=";块;仅适用于默认div不';I don’这一页一开始我就不工作

Javascript Style.display=";块;仅适用于默认div不';I don’这一页一开始我就不工作,javascript,jquery,html,css,display,Javascript,Jquery,Html,Css,Display,这就是我的想法:我正在为我的工作室的网站编程,但只需一个页面。当你点击一个按钮继续。。例如,在“原因为什么”页面中,您不是重定向而是页面内容发生变化!基本上,代码非常简单,如下所示: 函数soloprenota(){ document.getElementById(“article1”).style.display=“block”; document.getElementById(“article2”).style.display=“无”; document.getElementById(“a

这就是我的想法:我正在为我的工作室的网站编程,但只需一个页面。当你点击一个按钮继续。。例如,在“原因为什么”页面中,您不是重定向而是页面内容发生变化!基本上,代码非常简单,如下所示:

函数soloprenota(){ document.getElementById(“article1”).style.display=“block”; document.getElementById(“article2”).style.display=“无”; document.getElementById(“article3”).style.display=“无”; } 函数soloilnostrosuono(){ document.getElementById(“article1”).style.display=“无”; document.getElementById(“article2”).style.display=“block”; document.getElementById(“article3”).style.display=“无”; } 函数soloreasonwhy(){ document.getElementById(“article1”).style.display=“无”; document.getElementById(“article2”).style.display=“无”; document.getElementById(“article3”).style.display=“block”; }只需添加
soloprenota()
作为
的最后一行。这将使soloprenota成为默认值

检查下面的示例

函数soloprenota(){ document.getElementById(“article1”).style.display=“block”; document.getElementById(“article2”).style.display=“无”; document.getElementById(“article3”).style.display=“无”; } 函数soloilnostrosuono(){ document.getElementById(“article1”).style.display=“无”; document.getElementById(“article2”).style.display=“block”; document.getElementById(“article3”).style.display=“无”; } 函数soloreasonwhy(){ document.getElementById(“article1”).style.display=“无”; document.getElementById(“article2”).style.display=“无”; document.getElementById(“article3”).style.display=“block”; } soloprenota()

    索洛普雷诺塔 soloilnostrosuono soloprenota
第一条 第二条 第3条

    索洛普雷诺塔 soloilnostrosuono soloprenota
第一条 第二条 第三条
使用此短代码可使用此脚本并按需显示

function soloprenota(e) {
  var detectid = e;
  if(detectid=="article1"){
  document.getElementById("article1").style.display = "block";
  document.getElementById("article2").style.display = "none";
  document.getElementById("article3").style.display = "none";
  } else if(detectid=="article2"){
  document.getElementById("article2").style.display = "block";
  document.getElementById("article1").style.display = "none";
  document.getElementById("article3").style.display = "none";
  } else if(detectid=="article3"){
  document.getElementById("article3").style.display = "block";
  document.getElementById("article1").style.display = "none";
  document.getElementById("article2").style.display = "none";
  }
}

//Style Sheet
#article1 {
    display:none;
}
#article2 {
    display:none;
}
#article3 {
    display:none;
}

<nav>
  <ul>
    <li onclick="soloprenota('article1')">soloprenota</li>
    <li onclick="soloilnostrosuono('article2')">soloilnostrosuono</li>
    <li onclick="soloreasonwhy('article3')">soloprenota</li>
    </ul>
  </nav>
<div id="article1">article 1</div>
<div id="article2">article 2</div>
<div id="article3">article 3</div>
函数soloprenota(e){
var detectid=e;
如果(detectid==“第1条”){
document.getElementById(“article1”).style.display=“block”;
document.getElementById(“article2”).style.display=“无”;
document.getElementById(“article3”).style.display=“无”;
}否则如果(detectid==“第2条”){
document.getElementById(“article2”).style.display=“block”;
document.getElementById(“article1”).style.display=“无”;
document.getElementById(“article3”).style.display=“无”;
}否则,如果(detectid==“第3条”){
document.getElementById(“article3”).style.display=“block”;
document.getElementById(“article1”).style.display=“无”;
document.getElementById(“article2”).style.display=“无”;
}
}
//样式表
#第1条{
显示:无;
}
#第二条{
显示:无;
}
#第三条{
显示:无;
}
    索洛普雷诺塔 Soloilnostrosuno(第2条) 索洛普雷诺塔
第一条 第二条 第三条
在页面加载时,您想要实现什么?第一个DIV应该是唯一可见的吗?好的,我还没有尝试过你的代码,但这不是必需的:它让我想到为所有DIV编写“display:none”;除了css样式文档中的默认DIV之外,它工作正常!不过,谢谢。:)
function soloprenota(e) {
  var detectid = e;
  if(detectid=="article1"){
  document.getElementById("article1").style.display = "block";
  document.getElementById("article2").style.display = "none";
  document.getElementById("article3").style.display = "none";
  } else if(detectid=="article2"){
  document.getElementById("article2").style.display = "block";
  document.getElementById("article1").style.display = "none";
  document.getElementById("article3").style.display = "none";
  } else if(detectid=="article3"){
  document.getElementById("article3").style.display = "block";
  document.getElementById("article1").style.display = "none";
  document.getElementById("article2").style.display = "none";
  }
}

//Style Sheet
#article1 {
    display:none;
}
#article2 {
    display:none;
}
#article3 {
    display:none;
}

<nav>
  <ul>
    <li onclick="soloprenota('article1')">soloprenota</li>
    <li onclick="soloilnostrosuono('article2')">soloilnostrosuono</li>
    <li onclick="soloreasonwhy('article3')">soloprenota</li>
    </ul>
  </nav>
<div id="article1">article 1</div>
<div id="article2">article 2</div>
<div id="article3">article 3</div>