简体   繁体   English

'checked'为空或不是对象-仅IE

[英]'checked' is null or not an object - only IE

This problem exists only in IE browser, in mozilla its working fine... i have to delete a row on click on checkbox.... Here is my code : 仅在IE浏览器中存在此问题,在mozilla中其工作正常...我必须在单击复选框时删除一行。...这是我的代码:

<table width="100%" id="seller">
<tr id="row_1" class="row">
 <td><input type="checkbox" name="delete_seller" id="delete_seller" value="1" /></td>
</tr>
<tr id="row_2" class="row">
 <td><input type="checkbox" name="delete_seller" id="delete_seller" value="2" /></td>
</tr>
</table>
<input type="button" id="delete" name="delete" value="Delete" onclick="delete_row('seller')"/>

    var delete_ids = [];
    function delete_row(tableID){
      var rows = document.getElementsByClassName('row');
      var delItems = document.getElementsByName('delete_seller');

      for(var i=0;i < rows.length;i++){
        if(delItems[i].checked == true){
          delete_ids.push(rows[i].id);
          jQuery(rows[i]).remove();
          i = i-1;
        }
      }
}

Showing error on page : 'checked' is null or not an object . 在页面上显示错误: 'checked'为null或不是object
can one please tell me the fix . 能告诉我解决的办法吗。

thanks in advance, sri.. 预先感谢,斯里兰卡。

You can replace the loop with jQuery, like this: 您可以使用jQuery替换循环,如下所示:

delete_ids.push.apply(delete_ids,
    $('tr.row:has(.delete:checked)').remove()
        .map(funcion() { return this.id; })
);

This will select all tr.row element that :has a .delete element that is :checked . 这将选择所有tr.row元素:has一个.delete是元素:checked
It calls .remove() to remove the rows, then calls .map() to get the rows' IDs, and applies the push function to add them to your array. 它调用.remove()删除行,然后调用.map()获取行的ID,然后应用push函数将其添加到数组中。

You can avoid the push.apply by changing it to 您可以通过将push.apply更改为

    $('tr.row:has(.delete:checked)').remove()
        .each(funcion() { delete_ids.push(this.id); });

EDIT : Try this: 编辑 :试试这个:

    $('tr.row:has(.delete_seller:checked)')
        .each(funcion() { delete_ids.push(this.id); })
        .remove();

Both your checkboxes and your button are called "delete" and your delItems variable will contain the button as well. 您的复选框和按钮都称为“删除”,并且delItems变量也将包含按钮。 The button doesn't have a checked attribute, which I'm guessing is where IE complains about it. 该按钮没有选中的属性,我猜这是IE抱怨的地方。

Although in the example you give there are fewer elements with class 'row' than there are elements with name 'delete' which should mean you don't get to the point in the loop where delItems[i] refers to the button. 尽管在示例中您给出的类“行”的元素少于名称为“删除”的元素,这应意味着您不会到达delItems [i]引用按钮的循环中。 Unless there are more elements class 'row' on the page. 除非页面上有更多元素类“行”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM