-1
我有一个表格,我希望能够选中标题中的一个复选框以选择该表格中的所有复选框。这通常应该是一个非常简单的事情,但它根本不在这里工作。当我在JSfiddle上运行示例代码时,它可以工作。当在我的开发环境中运行它并检查顶部框时,如果我把alert()它会提醒,但仍然不检查其余的复选框。任何想法为什么?选中一个复选框以选择多个复选框
[JS fiddle][1]
http://jsfiddle.net/pkvLqe1d/
这里是我的开发环境中的代码:
<div class="content" id="content">
<form id="selectContent" method="post" class="grow">
<table class="static" style="width:1000px;">
<thead>
<tr>
<th>
<b>Id</b>
</th>
<th>
<b>Name</b>
</th>
<th>
<label><input type="checkbox" name="select-all" id="select-all" /></label>
</th>
</tr>
</thead>
<tbody>
<?php
foreach($a as $b)
{
echo "<tr>";
echo "<td>$b->id</td>";
echo "<td>$b->name</td>";
echo "<td><label><input type='checkbox' name='id[]' value='".trim($b->id)."' class='round'></label></td>";
echo "</tr>";
}
?>
</tbody>
</table>
</form>
</div>
<script>
//Listen for click on toggle checkbox
$('#select-all').click(function(event) {
if(this.checked) {
// Iterate each checkbox
$(':checkbox').each(function() {
this.checked = true;
});
}
});
</script>
好吧,当我运行你的小提琴,它的工作原理,就像你说的。这意味着还有其他问题,并且您没有向我们展示您的真实代码。这将很难帮助你。 (SO的一个要求是说明问题的“最小工作示例”,我们可以请看看吗?) –
这里是一个JSfiddle,它不工作:http://jsfiddle.net/04btkoL5/ – mediasurface
当我在Firebug调试器中运行它,它在参数列表后显示“SyntaxError:missing)”。 (由于JSFiddle的工作方式,行号并没有用。)当用调试器运行它时会发生什么? –