我有這樣的標籤:獲取上單擊錶行ID(HTML + JS)
<td align="center">
<div class="dropdown">
<button onclick="DropdownShow(this)" class="btn btn-default glyphicon glyphicon-picture"></button>
<div id="@TableRowId" class="dropdown-content">
<a href="#">Show</a>
<a href="#">Edit</a>
</div>
</div>
</td>
和JS功能:
function DropdownShow(element) {
var elm = document.getElementById(element.querySelector(".dropdown-content").id);
elm.classList.toggle('show');
}
我想,當我上的圖像glyphicon單擊表,用class =「dropdown-content」顯示下拉div標籤。要做到這一點,我需要每行ID,並且我在變量@TableRowId上。我怎樣才能做到這一點?
該div是元素的下一個同級,而不是孩子。所以你想要element.nextSibling而不是element.querySelector。 – Shilly
'@ TableRowId'不是一個有效的ID –
你的桌子在哪裏?你的行在哪裏?我們沒有看到它們。 –