我想隱藏一堆使用javascript的表格行。 我想我已經得到了大部分的代碼,我只是不知道爲什麼它沒有運行隱藏。使用jQuery隱藏表格行
任何幫助表示讚賞。
的代碼是:
<script type="text/javascript">
function hideButton()
{
$("#showHideButton").on("click", function (e) {
var button = e.target;
var node = $(button).parent().parent().next();
while (!node.hasClass("service-header")) {
if ($(node).is(":visible")) {
$(node).hide();
} else {
$(node).show();
}
node = node.next();
}
})}
</script>
的HTML是:
for (loopHere)
{
echo "<tr class='service-header'><th>InfoHere</th><th>" . InfoHere . "<button style='float:right' type='button' id='showHideButton' class='btn btn-default' onclick='hideButton()'><span class='dashicons dashicons-arrow-down-alt2'></span></button></th></tr>";
echo "<tr><td>More Stuff</td></tr>";
echo "<tr><td>More Stuff</td></tr>";
}
loop
我有不知道爲什麼它不會隱藏在點擊的行,我已經測試了一表具有多個具有類service-header的行,但沒有任何運氣。
'e'沒有在事件處理程序'hideButton()'中定義,你也是附件g每次單擊元素時發生新的「單擊」事件。 「while」循環的目的是什麼? – guest271314
發佈HTML過..也或者,定義的功能點擊或使用事件處理程序,但不是兩個 –
你可以標記以及 – guradio