问题描述
我一直在向datatables.net表中的每一行动态添加复选框.但是,当我选中这些框时,html不会显示任何选中的属性,因此不允许我仅关注带有选中复选框的行.如果我将复选框设置为选中属性,则可以,选中属性可见.这里的代码显示了我如何尝试检查选中的属性...
I have been dynamically adding checkboxes to each row within a table - datatables.net . However, when I check the boxes, the html does not show any checked attribute which then does not allow me to only focus on the rows with checked checkboxes. If I set the checkbox with the checked attribute, then yes, the checked attribute is visible. The code here shows how I'm trying to check the checked attribute...
var filtered_rows = example_data_table._('tr', {"filter":"applied"});
$.each(filtered_rows, function(i, el){
// If not checked, do not include
if(!$(el[0]).is(':checked')){
console.log(el[0]);
return true;
}else{
window.alert("HIT");
}
...
以下是我将元素追加到datatables.net表中的方式...
and the following is how I'm appending the element to the datatables.net table...
var checkbox = $("<input type='checkbox'
id='checkbox_" + o.example_id + "' />");
...
tmp = [checkbox[0].outerHTML,
...];
table_data.push(tmp);
...
example_data_table.fnClearTable(false);
example_data_table.fnAddData(table_data);
在控制台中,我得到的只是该消息n次:
In the console, all I get is this message n times:
<input type="checkbox" id="checkbox_3895"> examples.php:189
我想,我想知道为什么即使选中了复选框也从不包含选中的属性吗?
I guess, I'm wondering why the checked attribute is never included even when I have checked the checkbox?
推荐答案
HTML标记属性< inputchecked ="
实际上并非旨在显示运行时元素的状态,但要定义页面首次呈现时的默认状态.
The HTML markup attribute <input checked=""
is not actually designed to show the state of the element at runtime moment, but to define the default state of it when the page renders for the first time.
MDN<输入>文档 状态:
您可以定位的唯一变化状态是Js DOM属性 checked
:
The only varying of checked state you can target is the Js DOM property checked
:
document.getElementById('myInput').checked; //(true / false)
或Css伪:checked
:
#myInput:checked {
}
这篇关于没有选中属性的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!