2014-02-05 15 views
-4

这是我的代码?如何在<tr>内弹出div?

<tr style="display: none"><td colspan="5"> 
     <div id="sub-155642" style="display:none;"> 
      <table width="100%"> 
       <tr> 
        <td class="inner-table"></td> 
        <td class="inner-table">Document No</td> 
        <td class="inner-table">Document Type</td> 
        <td class="inner-table" id="amount-row">Total Amount</td> 
       </tr> 
      </table> 
     </div > 
    </td> 
</tr> 

我想从Javascript或jQuery的弹出内部<div id="sub-155642"></div>内容。请帮帮我。

+0

究竟你弹出是什么意思? – Itay

+0

这写的很差。 Html元素ID在整个页面上必须是唯一的,但这里的“tr”和“div”具有相同的ID。 – cubaguest

+0

我想弹出里面的表格 – sanji

回答

1

您可以克隆表,一些弹出窗口并显示它:

HTML

<table> 
    <tr id="sub-155642" style="display: none"> 
    <td colspan="5"> 
     <div id="sub-155642" style="display:none;"> 
     <table width="100%"> 
      <tr> 
      <td class="inner-table"></td> 
      <td class="inner-table">Document No</td> 
      <td class="inner-table">Document Type</td> 
      <td class="inner-table" id="amount-row">Total Amount</td> 
      </tr> 
     </table> 
     </div> 
    </td> 
    </tr> 
</table> 
<button onclick="popup()">Pop-up</button> 

的JavaScript

var popupEl; 

function popup() { 
    var divEl, 
     tableEl, 
     xEl; 
    if(!popupEl) { 
    // Find table 
    tableEl = document.querySelector('#sub-155642 > table'); 
    divEl = tableEl.parentNode; 
    // Create popup and clone table to it 
    popupEl = document.createElement('div'); 
    popupEl.innerHTML = divEl.innerHTML; 
    popupEl.setAttribute('style', 'position:fixed;top:50%;left:50%;width:300px;height:100px;margin-left:-150px;margin-top:-50px;border:1px solid gray'); 
    // Show popup 
    document.querySelector('body').appendChild(popupEl); 
    } else { 
    document.querySelector('body').removeChild(popupEl); 
    popupEl = null; 
    } 
} 

JSBin:http://jsbin.com/OyeXiNu/1/edit

否则,你可以做包装表可见(但可以肯定的ID是唯一的):

的JavaScript

var div = document.getElementById('sub-155642'); 
div.style.display = 'block'; 
div.parentNode.parentNode.style.display = 'table-row';