Microsoft JScript运行时错误:无法获取属性'的值;选中':对象为null或仅在IE9中未

Microsoft JScript runtime error: Unable to get value of the property 'checked': object is null or undefined only in IE9

本文关键字:null 中未 IE9 对象 Microsoft 运行时错误 获取 属性 的值 JScript 选中      更新时间:2023-09-26

我必须选中复选框中的项目,然后单击添加按钮,将选中的项目添加到框中。选中复选框中的项目后,单击添加按钮,我得到以下错误。它只出现在IE9中。

Microsoft JScript运行时错误:无法获取属性"checked"的值:对象为null或未定义

我的js页面代码是:

document.onkeyup = fnRemoveSelectedItems;
//Global variables 
var cssGridrow="gridrow";
var cssGridalteraterow="gridalteraterow";
var selectedItems=new String();
var pickItemSelected="1";
var isOnsiteLoc = 0;
/*Function that adds the selected items to the text box in the pick up box */
function fnPickUpAdd(btnOKClientId, lstFromClientId, txtBoxClientId, ColumnToTake) {
    //enable the ok button
    document.getElementById(btnOKClientId).disabled=false;
    //From grid Object
    var lstFrom=document.getElementById(lstFromClientId);
    //to textbox Object
    var txtBoxObject=document.getElementById(txtBoxClientId);
    //If the lstFromClienId is location then iteration occurs.
    if (lstFromClientId.search(/Location/i) > 0) {
        //Iterating only with in the grid rows to check if the location is onsite
        for (var i = 1; i < lstFrom.rows.length; i++) {
            var CheckBoxId = lstFrom.rows[i].cells[0].childNodes[0].id;
            if (document.getElementById(CheckBoxId).checked && lstFrom.rows[i].cells[6].innerText != null && lstFrom.rows[i].cells[6].innerText == "True") {
                isOnsiteLoc = 1;
                break;
            }
        }
    }
    //Iterating only with in the grid rows to get the selected SOIDs
    for(var i=0;i<lstFrom.rows.length; i++) {
        if(lstFrom.rows[i].className==cssGridrow || lstFrom.rows[i].className==cssGridalteraterow) {
            var childRowCheckBoxId=lstFrom.rows[i].cells[0].childNodes[0].id;
            if(childRowCheckBoxId!= "") {
                if(document.getElementById(childRowCheckBoxId).checked) {
                    //locationmatchFor = "1" for all scenarios except for location pick up in search
                    // so for this we would take the value in cells[1]
                    if(ColumnToTake=='1'){ //From Preferences 
                        if(findMatchValue(txtBoxObject, lstFrom.rows[i].cells[1].innerText)==false) {
                            //show that in the text box
                            txtBoxObject.innerHTML+="<span onclick='fnSelectItem(this)' isItem=1>"+lstFrom.rows[i].cells[1].innerText+";</span>";
                            //Form this to pass the selected items to the parent page
                            //selectedItems+=(lstFrom.rows[i].cells[1].innerText)+":"+(lstFrom.rows[i].cells[2].innerText);
                            selectedItems+=(lstFrom.rows[i].cells[1].innerText);
                            selectedItems+=";";
                        }
                    }
                }
            }
        }
    }
}

可能没有您试图在以下行中访问的DOM属性id

var CheckBoxId = lstFrom.rows[i].cells[0].childNodes[0].id;

var childRowCheckBoxId=lstFrom.rows[i].cells[0].childNodes[0].id;

id是属性吗?如果是这样,你可以试着做

getAttribute('id')

在html的头上添加以下内容:

<meta http-equiv="X-UA-Compatible" content="IE=8" />

我的猜测是,在For循环中,您正在循环通过网格的最后一行。检查Length属性,查看计数中是否包含"页码行"。i < Length - 1对我有效。