2013-08-27 3 views
1

이 사이트에서 전문가의 도움이 필요합니다.표를 복사하고 새 팝업 창을 엽니 다.

버튼을 클릭하면 기존 테이블 ('데이터')을 복사하고 새 팝업 창을 열고 document.write를 사용하여 이전 페이지의 테이블을 씁니다. 새로운 것.

<!DOCTYPE html> 
<html> 

    <head> 
     <meta http-equiv="Content-Language" content="en-ca"> 
    </head> 

    <body> 
     <table id="data" border="1" cellspacing="1" width="100" id="table1"> 
      <tr> 
       <th>Fruits</th> 
       <th>Vegetables</th> 
       <th>Colors</th> 
       <th>Quantity</th> 
       <th>Price</th> 
      </tr> 
      <tr> 
       <td>Apples</td> 
       <td>Carrots</td> 
       <td>red</td> 
       <td>10</td> 
       <td>0.99</td> 
      </tr> 
      <tr> 
       <td>Pears</td> 
       <td>Celery</td> 
       <td>blue</td> 
       <td>24</td> 
       <td>1.00</td> 
      </tr> 
      <tr> 
       <td>Mangos</td> 
       <td>Broccoli</td> 
       <td>green</td> 
       <td>12</td> 
       <td>1.50</td> 
      </tr> 
      <tr> 
       <td>Oranges</td> 
       <td>Cauliflower</td> 
       <td>purple</td> 
       <td>48</td> 
       <td>1.25</td> 
      </tr> 
     </table> 
     <br> 
     <input type="button" value="test it" /> 
    </body> 

</html> 

답변

0

Here은 작업 예입니다.

<input type="button" value="Open popup" onclick="openPopup();" /> 

클릭 처리기 기능 :

function openPopup() { 
    var popup = window.open("", "", "width=640,height=480,resizeable,scrollbars"), 
     table = document.getElementById("data"); 

    popup.document.write(table.outerHTML); 
    popup.document.close(); 
    if (window.focus) 
    popup.focus(); 
} 
+0

window.open 종종 널 (null)을 반환합니다

버튼을 클릭 핸들러를 필요 – CashCow

0

것은 먼저 버튼의 onclick 함수를 추가합니다 :

스크립트에서
<input type="button" value="test it" onclick="openWin()" /> 

:

기능 openWin() {

myWindow = window.open ('', '' , 'width = 200, height = 100'); myWindow.document.write (document.getElementById ('data'). outerHTML);

myWindow.focus();

} 그것은 그게

.

브라우저간에 outerHTML 속성 호환성이 확실하지 않습니다. 한번 확인해주십시오.

관련 문제