1

嗨,当我单击按钮时,我正在尝试使用 jquery 将 div 替换为新的 div。目前,当我单击按钮时,新的 div 没有显示,当我单击按钮时它只是空白。我怎样才能看到隐藏的?

<!DOCTYPE html>
<html>
<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button id="change">Change</button>
  <div id="table1">
<table >
 <tr>
 <td>
 this is table1
 </td>
</tr>
 </table>
</div>


 <div id="table2" style="display: none">
 <table >
  <tr>
  <td>
   this is table2
   </td>
    </tr>
</table>
 <div>


 <script>
  $("#change").click(function () {
   $("#table1").replaceWith( $("#table2") );
 });
  </script>

  </body>
 </html>

一个例子在这里:http: //jsfiddle.net/S8HxM/1/

4

2 回答 2

1

由于您应用的样式,它是空的table2

 style="display: none"

table1隐藏的表替换;-)所以你必须添加这个:

$("#table1").replaceWith( $("#table2").show() );

工作:http: //jsfiddle.net/qbRcK/2/

于 2012-06-09T13:09:32.260 回答
-1

尝试使用 $("#table2").html() 更改代码

于 2012-06-09T12:54:36.603 回答