jqGrid行选择的奇怪行为

我有这种非常不寻常的行为,让我来描述一下这个问题。

jqgrid一共有14条记录,首先它设置为rowNum:10,当从下拉列表中选择显示50行所有记录容纳时,但在Firefox 5中我选择第11行 (Name as asd )时也选择第10行。 它在IE8中表现不同。

在IE8中,它给出了以下错误

 Webpage error details Message: 'className' is null or not an object Line: 2496 Char: 4 Code: 0 URI: http://au1642163:10070/csm/view/include/js/jquery.jqGrid.min.js 

这是IE8的图像

在此处输入图像描述

我的jqgrid代码

 var xml=client.responseText; var xmlDoc = $.parseXML(xml); var $xml = $(xml); xml=xml.replace(/1/g, ""+productMap['1']); xml=xml.replace(/2/g, ""+productMap['2']); $('#configDiv').empty(); $('#configDiv').html( '
' + '
'); var grid = jQuery("#list1"); var iconAlert; getColumnIndexByName = function (grid, columnName) { var cm = grid.jqGrid('getGridParam', 'colModel'), i = 0, l = cm.length; for (; i < l; i += 1) { if (cm[i].name === columnName) { return i; // return the index } } return -1; }, grid = jQuery("#list1"), iconAlert = ''; grid.jqGrid({ datastr : xml, datatype: 'xmlstring', colNames:['cfgId','Name', 'Host','Operating System', 'Description','Product', 'Type', 'Last Updated Time','Last Updated By','',''], colModel:[ {name:'cfgId',index:'cfgId', width:90, align:"left", hidden:true}, //{name:'updateDate',index:'updateDate', width:12, align:'center', formatter: oldConfigurationWarning }, {name:'cfgName',index:'cfgName', width:70, align:"left", formatter: 'showlink', formatoptions: {baseLinkUrl: '#'} }, {name:'hostname',index:'hostname', width:70, align:"left"}, {name:'osname',index:'osname', width:90, align:"left"}, {name:'cfgDesc',index:'cfgDesc', width:90, align:"left"}, {name:'productId',index:'productId', width:40, align:"left"}, {name:'cfgType',index:'cfgType', width:50, align:"left"}, {name:'updateDate',index:'updateDate',sorttype:'Date', width:120, align:"left"}, {name:'emailAddress',index:'emailAddress', width:120, align:"left"}, {name:'absolutePath',index:'absolutePath', width:90, align:"left", hidden:true}, {name:'fileName',index:'fileName', width:90, align:"left", hidden:true} ], pager : '#gridpager', rowNum:10, rowList:[10,50,100], scrollOffset:0, height: 'auto', emptyrecords: 'No configurations loaded', autowidth:true, viewrecords: true, gridview: true, multiselect: true, xmlReader: { root : "list", row: "Response", userdata: "userdata", repeatitems: false }, loadComplete: function () { var count = grid.getGridParam(); var ts = grid[0]; if (ts.p.reccount === 0) { grid.hide(); emptyMsgDiv.show(); } else { grid.show(); emptyMsgDiv.hide(); } //for showlink and icon alert having date difference more than 90 days var iRow, row, trClasses, $cell, icfgName = getColumnIndexByName(grid, 'cfgName'), iupdateDate = getColumnIndexByName(grid, 'updateDate'), mygrid = grid[0], rows = mygrid.rows, cRows = rows.length, myLink = function (e) { var $td = $(e.target).closest('td'), text = $td.text(), $tr = $td.closest('tr'), rowid = $tr[0].id; goToViewAllPage(rowid); }; for (iRow = 0; iRow 0) { // the row is a standard row (only if subGrid:true are used) /*if ($(row.cells[iupdateDate]).text() === 'Science') { $cell.prepend(iconAlert); }*/ var cellvalue1,firstDate,secondDate; $cell = $(row.cells[icfgName]); cellvalue1=$(row.cells[iupdateDate]).text(); firstDate = new Date(); //console.info(cellvalue1+", "+cellvalue1.length); //var cellvalue1="08-18-2011 11:49:01"; if(cellvalue1.length>25) { secondDate=new Date(); //secondDate = secondDate.substring(0, secondDate.length-3); if(diffOf2Dates(firstDate,secondDate,true)>=expireCondition) { $cell.prepend(iconAlert); } $cell.click(myLink); } else { secondDate = cellvalue1.substring(0, cellvalue1.length-6); if(diffOf2Dates(firstDate,secondDate,false)>=expireCondition) { $cell.prepend(iconAlert); } $cell.click(myLink); } } } }, onSelectRow: function(id,status){ //var rowData = jQuery(this).getRowData(id); } }); grid.jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false}); jQuery("#m1").click( function() { var s; s = grid.jqGrid('getGridParam','selarrrow'); alert(s); }); var myGrid = $("#list1"); $("#cb_"+myGrid[0].id).hide(); // place div with empty message insde of bdiv emptyMsgDiv.insertAfter(grid.parent()); } };

我的XML响应

   704 IIR Windows1 asda Production csmclientIIR.xml ../webapps/csm/files//12345/csmclientIIR.xml asimon@ABC.com 12345 IIR 2011-09-07 10:55:31.0 IST 2011-09-07 10:55:31.0 IST 1 1 Windows_NT   717 ilmwin asd Production csmclientin164302.xml ../webapps/csm/files//12345/csmclientin164302.xml asimon@ABC.com 12345 IN164302 2011-09-07 16:45:03.0 IST 2011-09-07 16:45:03.0 IST 1 2 Windows_NT   718 ilmwin1 asdasd Production csmclientin164302.xml ../webapps/csm/files//12345/csmclientin164302.xml asimon@ABC.com 12345 IN164302 2011-09-07 16:46:35.0 IST 2011-09-08 10:19:26.0 IST 2 2 Windows_NT   723 ilm linux asd Production csmclientestilo.xml ../webapps/csm/files//12345/csmclientestilo.xml asimon@ABC.com 12345 estilo 2011-09-08 14:20:09.0 IST 2011-09-08 14:20:09.0 IST 1 2 Linux   696 ILMwin1 asfas Production csmclientin164302.xml ../webapps/csm/files//12345/csmclientin164302.xml mkuamrln@ABC.com 12345 IN164302 2011-09-06 16:15:06.0 IST 2011-09-06 16:15:06.0 IST 1 2 Windows_NT   697 ILMlin dgds Production csmclientestilo.xml ../webapps/csm/files//12345/csmclientestilo.xml mkuamrln@ABC.com 12345 estilo 2011-09-06 16:20:58.0 IST 2011-09-06 16:20:58.0 IST 1 2 Linux   706 ILM linux wwrwrwr Production csmclientestilo.xml ../webapps/csm/files//12345/csmclientestilo.xml mkuamrln@ABC.com 12345 estilo 2011-09-07 14:22:03.0 IST 2011-09-07 14:22:03.0 IST 1 2 Linux   698 test1 asfta Production csmclientgcslpar1.xml ../webapps/csm/files//12345/csmclientgcslpar1.xml asimon@ABC.com 12345 gcslpar1 2011-09-06 17:14:31.0 IST 2011-09-08 10:20:15.0 IST 2 1 AIX   699 test2 adAD Production csmclientgcslpar2.xml ../webapps/csm/files//12345/csmclientgcslpar2.xml mkuamrln@ABC.com 12345 gcslpar2 2011-09-06 17:14:46.0 IST 2011-09-06 17:14:46.0 IST 1 1 AIX   702 IIR Windows asdad Production csmclientIIR.xml ../webapps/csm/files//12345/csmclientIIR.xml asimon@ABC.com 12345 IIR 2011-09-07 10:47:10.0 IST 2011-09-07 10:47:10.0 IST 1 1 Windows_NT   687 asd a Production csmclientestilo.xml ../webapps/csm/files//12345/csmclientestilo.xml asimon@ABC.com 12345 estilo 2011-09-06 13:28:28.0 IST 2011-09-06 13:28:28.0 IST 1 1 Linux   688 asd1 asd Production csmclientbuckeye.ABC.com.xml ../webapps/csm/files//12345/csmclientbuckeye.ABC.com.xml asimon@ABC.com 12345 buckeye.ABC.com 2011-09-06 13:30:10.0 IST 2011-09-06 13:30:10.0 IST 1 1 Linux   701 NULL asda Production csmclientin164302.xml ../webapps/csm/files//12345/csmclientin164302.xml asimon@ABC.com 12345 IN164302 2011-09-07 10:43:19.0 IST 2011-09-08 16:44:00.0 IST 2 2 Windows_NT   705 Sunos config asdasd Production csmclientzenvo.xml ../webapps/csm/files//12345/csmclientzenvo.xml asimon@ABC.com 12345 zenvo 2011-09-07 11:22:56.0 IST 2011-09-07 11:22:56.0 IST 1 1 SunOS   

您应该测试自己发布的代码。 你应该仔细阅读答案中的问题 。 如果您不想遇到所述问题,则应以其他方式设置问题。 不过,我会回答你当前的问题。

当前代码包含许多未定义的函数和变量。 而且它的语法错误很小。 最重要的一个是

 var grid = jQuery("#list1"); var iconAlert; getColumnIndexByName = function (grid, columnName) { ... }, grid = jQuery("#list1"), iconAlert = ' 

你不应该两次定义相同的变量,并且以任何方式应该替换';' 在var iconAlert;的ent var iconAlert; 逗号将变量getColumnIndexByName定义为函数。

开头的代码( xml=xml.replace(/1/g, ""+productMap['1']); )我根本无法理解。 如果你有$xml并且可以使用jQuery来选择和修改任何XML元素,为什么你需要对XML进行奇怪的修改。

如果你继续使用如此脏的代码,你可能会遇到更严重的问题。 我建议您始终在JSLint中validation您的代码。 例如,您可以包含JSLint选项

 /*global $, jQuery */ /*jslint devel: true, browser: true, vars: true, white: true, plusplus: true*/ 

在准备测试示例的所有工作之后,只有结果代码没有您描述的问题。