1

我想制作一个网络应用程序,其中有多个页面但是没有使用ancchor标记的没有java脚本的onclick函数

     <html>
     <head>
      <script>
     function show(shown, hidden) {
     document.getElementById(shown).style.display='block';
      document.getElementById(hidden).style.display='none';
     return false;
     }
    </script>
    </head>
   <body>


   <div id="Page1">
     Content of page 1
     <a href="#" onclick="return show('Page2','Page1');">Show page 2</a>
    </div>

    <div id="Page2" style="display:none">
    Content of page 2
     <a href="#" onclick="return show('Page1','Page2');">Show page 1</a>
    </div>

   </body>
   </html>
4

1 回答 1

1

您可以使用 CSS 和复选框来获得此SITE上所写的这种行为。

复选框是唯一具有两种不同状态的 HTML 元素,可以通过:checked属性由 CSS 导出/评估。

引用自http://www.inserthtml.com/2012/04/css-click-states/
HTML:

<form class="clickable"> 
  <label for="the-checkbox">Click Me!</label>
  <input type="checkbox" id="the-checkbox" /> 
  <!-- This is the div we want to appear and disappear -->
  <div class="appear">Some text to appear</div>
</form>

CSS:

.clickable .appear { 
  display: none;
}

.clickable input:checked ~ .appear {
  display: block;
}

查看该页面底部的演示。

要在两个以上的页面中进行选择,您可以使用单选按钮。未经测试,仅作为一个想法;)

于 2012-10-16T07:42:37.043 回答