我正在构建一个循环来从数据库中获取所有行,并将它们输出到表的行中。
我在选中时会在表格的标题处添加一个全选复选框,它会选中全部,当取消选中时,它会取消选择全部。
如果有人能给我支持,我无法让它工作。
<div class="table">
<div class="table-head">
<div class="column" data-label="select"><input type="checkbox" id="selectall">Select all</input></div>
<div class="column" data-label="id">ID</div>
<div class="column" data-label="avatar">Avatar</div>
<div class="column" data-label="username">Username</div>
<div class="column" data-label="email">Email</div>
<div class="column" data-label="active">Active</div>
<div class="column" data-label="level">Level</div>
<div class="column" data-label="modify">Modify</div>
</div>
<?php
$request = mysql_query('SELECT * FROM users');
while ($table = mysql_fetch_array($request)) {
echo '<div class="row">';
echo '<div class="column" data-label="select"><input type="checkbox" class="selectedId" name="selectedId" value="' . $table['id'] . '" onclick="resetSelectAll();" /></div>';
echo '<div class="column" data-label="id">' . $table['id'] . '</div>';
echo '<div class="column" data-label="avatar"><img src="uploads/' . $table['profile_image'] . '" alt=""></div>';
echo '<div class="column" data-label="username">' . $table['username'] . '</div>';
echo '<div class="column" data-label="email">' . $table['email'] . '</div>';
echo '<div class="column" data-label="active">' . $table['active'] . '</div>';
echo '<div class="column" data-label="level">' . $table['user_level'] . '</div>';
echo '<div class="column" data-label="modify"><a href="edit.php"><img src="images/tool.png" alt=""></a> <a href="delete.php"><img src="images/delete.png" alt=""></a></div>';
echo '</div>';
}
?>
</div>
我的javascript:
<script language="javascript" type="text/javascript">
$('#selectall').on('click', function() {
$('.selectedId').attr('checked', $(this).is(":checked"));
});
</script>
有没有人注意到问题?
这是一个js小提琴http://jsfiddle.net/44g8stk7/1/