我想隐藏一堆使用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