2017-06-21 53 views

回答

0

你可以做的一件事是讓其他表已經在它下面,用CSS將display更改爲none,然後讓它在稍後用JavaScript執行。這裏是我的代碼在JQuery中完成:

$("#tableOne").click(function() { 
 
    $("#tableTwo").css("display", "block"); 
 
});
#tableTwo { 
 
display: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table id = "tableOne"> 
 
    <tr> 
 
    <td> 
 
     <button id = "demo">Click Me!</button> 
 
    </td> 
 
    </tr> 
 
</table> 
 
<table id = "tableTwo"> 
 
    <tr> 
 
    <td> 
 
     <p>Yay!</p> 
 
    </td> 
 
    </tr> 
 
</table>

這裏是我的常規的JavaScript:

  var demo = document.getElementById("demo"); 
 
      demo.onclick = function() { 
 
       document.getElementById("tableTwo").style.display = "block"; 
 
      }
#tableTwo { 
 
    display: none; 
 
}
<table id = "tableOne"> 
 
     <tr> 
 
     <td> 
 
      <button id = "demo">Click Me!</button> 
 
     </td> 
 
     </tr> 
 
    </table> 
 
    <table id = "tableTwo"> 
 
     <tr> 
 
     <td> 
 
      <p>Yay!</p> 
 
     </td> 
 
     </tr> 
 
    </table>

0
<html> 
<head> 
    <script> 
     function displaySecondTable(){ 
      document.getElementById("tableTwo").innerHTML=" (here is the code for your second table) "; 
     }  
    </script> 
</head> 

    <body> 

    <table id = "tableOne"> 
     <tr> 
     <td onclick="displaySecondTable()"> 
      Click here 
     </td> 
     </tr> 
    </table>  

    <table id = "tableTwo" /> 

</body> 
</html> 

可以在純JavaScript做;)

+0

非常感謝,兄弟。 這段代碼讓我省卻了很多麻煩,併爲我在辦公室的活動提供了一個燈光。 非常感謝! –

相關問題