0

我必须检查复选框中的项目,然后单击添加按钮,将选中的项目添加到一个框中。检查复选框中的项目并单击添加按钮后,我得到以下错误。它仅在 IE9 中发生。

Microsoft JScript 运行时错误:无法获取“已检查”属性的值:对象为空或未定义

我的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+=";";
                        }
                    }
                }
            }
        }
    }
}
4

3 回答 3

0

可能是您在以下几行中没有尝试访问的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')
于 2013-02-14T09:47:01.137 回答
0

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

<meta http-equiv="X-UA-Compatible" content="IE=8" />
于 2015-01-15T20:43:57.120 回答
-1

我的猜测是,在您的For循环中,您正在遍历网格的最后一行。检查Length属性,看看它是否在计数中包含“页码行”。 i < Length - 1为我工作。

于 2013-11-21T01:46:48.163 回答