我必须选中复选框中的项目,然后单击添加按钮,将选中的项目添加到框中。选中复选框中的项目后,单击添加按钮,我得到以下错误。它只出现在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
对我有效。