迭代复选框javascript?
我有一个用于选择/选中id=hap的所有复选框的功能迭代复选框javascript?,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一个用于选择/选中id=hap的所有复选框的功能 $(function () { $('#select-all').click(function (event) { var selected = this.checked; $('#hap').each(function () { this.checked = selected; }); }); }); 这是我选择全部的复选框
$(function () {
$('#select-all').click(function (event) {
var selected = this.checked;
$('#hap').each(function () { this.checked = selected; });
});
});
这是我选择全部的复选框
<input type='checkbox' id='select-all'><label for='select-all'>Delete all</label>
全部删除
我用它来选择php获取的数据
$data=mysql_query("SELECT*FROM comment where news_id='$id'");
$x=0;
while($a=mysql_fetch_array($data)){
$x++;
echo"
<td class='center'>
<input id='hap' type='checkbox' name='c_$x' value='$a[comment_id]'>
</td>";
}
$data=mysql\u query(“从评论中选择*,其中news\u id='$id');
$x=0;
而($a=mysql\u fetch\u数组($data)){
$x++;
回声“
";
}
但它只是在第一个循环中选择/检查一个数据,而没有选择另一个数据
有人知道它出了什么问题吗?ID是唯一的。如果一个页面上有多个ID,它将只使用第一个ID。如果您需要一个页面上的多个内容,则需要改用类。ID是唯一的。如果一个页面上有多个ID,它将只使用第一个ID。如果您需要一个页面上的多个内容,则需要改用类。ID是唯一的。如果一个页面上有多个ID,它将只使用第一个ID。如果您需要一个页面上的多个内容,则需要改用类。ID是唯一的。如果一个页面上有多个ID,它将只使用第一个ID。如果您需要一个页面上的多个内容,则需要改用类。尝试以下代码。将
id
更改为class
echo"
<td class='center'>
<input class='hap' type='checkbox' name='c_$x' value='$a[comment_id]'>
</td>";
试试这个代码。将
id
更改为class
echo"
<td class='center'>
<input class='hap' type='checkbox' name='c_$x' value='$a[comment_id]'>
</td>";
试试这个代码。将
id
更改为class
echo"
<td class='center'>
<input class='hap' type='checkbox' name='c_$x' value='$a[comment_id]'>
</td>";
试试这个代码。将
id
更改为class
echo"
<td class='center'>
<input class='hap' type='checkbox' name='c_$x' value='$a[comment_id]'>
</td>";
试试这个:
function actualizarSeleccion(){
$('.hap').each(function () {
this.checked = document.getElementById("select-all").checked;;
});
}
<input type='checkbox' id='select-all' onchange="actualizarSeleccion()"><label for='select-all'>Delete all</label>
函数{
$('.hap')。每个(函数(){
this.checked=document.getElementById(“全选”).checked;;
});
}
全部删除
试试这个:
function actualizarSeleccion(){
$('.hap').each(function () {
this.checked = document.getElementById("select-all").checked;;
});
}
<input type='checkbox' id='select-all' onchange="actualizarSeleccion()"><label for='select-all'>Delete all</label>
函数{
$('.hap')。每个(函数(){
this.checked=document.getElementById(“全选”).checked;;
});
}
全部删除
试试这个:
function actualizarSeleccion(){
$('.hap').each(function () {
this.checked = document.getElementById("select-all").checked;;
});
}
<input type='checkbox' id='select-all' onchange="actualizarSeleccion()"><label for='select-all'>Delete all</label>
函数{
$('.hap')。每个(函数(){
this.checked=document.getElementById(“全选”).checked;;
});
}
全部删除
试试这个:
function actualizarSeleccion(){
$('.hap').each(function () {
this.checked = document.getElementById("select-all").checked;;
});
}
<input type='checkbox' id='select-all' onchange="actualizarSeleccion()"><label for='select-all'>Delete all</label>
函数{
$('.hap')。每个(函数(){
this.checked=document.getElementById(“全选”).checked;;
});
}
全部删除
也许你喜欢这样:
$(function () {
$('#select-all').click(function() {
$(".hap").prop("checked", this.checked);
});
});
- 没有设置一个无用的变量
- 不使用每个方法(而是在对象的jquery集合中使用prop)
- 也许你喜欢这样:
$(function () {
$('#select-all').click(function() {
$(".hap").prop("checked", this.checked);
});
});
- 没有设置一个无用的变量
- 不使用每个方法(而是在对象的jquery集合中使用prop)
- 也许你喜欢这样:
$(function () {
$('#select-all').click(function() {
$(".hap").prop("checked", this.checked);
});
});
- 没有设置一个无用的变量
- 不使用每个方法(而是在对象的jquery集合中使用prop)
- 也许你喜欢这样:
$(function () {
$('#select-all').click(function() {
$(".hap").prop("checked", this.checked);
});
});
- 没有设置一个无用的变量
- 不使用每个方法(而是在对象的jquery集合中使用prop)