我在jsp中有一个动态填充的表。 我对所有表行使用了相同的 id。
在javascript中,我想检索所有id为“resultRow”的表格行元素。 js 中的 getElementsByName("resultRow") 在 IE10 中给出空的 htmlcollection
有没有其他方法可以获取匹配id的表格行
非常感谢任何帮助
`这是我的代码片段
In JSP:
<table id="subSecondTable" cellpadding="0" cellspacing="0">
<c:set var="loopCount" value="0" />
<c:forEach var="vinList" items="${requestScope.vehicleDetailsPO}">
<tr id="resultRow" height="10" class="handCursor"
onclick="rowColorChange('<c:out value="${loopCount}"/>','<c:out value="${vinList.vin}"/>');">
In js:
function rowColorChange(rowNumber,vin){
var rows=document.getElementsByName("resultRow");
var columns;
rowHighlighted=rowNumber;
for(i=0;i<rows.length;i++){
if (i==rowNumber){
rows[rowNumber].style.backgroundColor="blue";
//change the text color for the highlighted row
columns = rows[rowNumber].cells
for(j=0;j<columns.length;j++){
columns[j].style.color = "white";
}
//change the text color for the highlighted row
var previousRowint = parseInt(previousRow);
if (previousRow != rowNumber)
{
columns = rows[previousRowint].cells
for(j=0;j<columns.length;j++){
columns[j].style.color = "black";
}
}
previousRow=rowNumber;
if(vin==''){
vin = rows[parseInt(rowHighlighted)].cells[3].innerText;
}
document.getElementById("txtCopyVin").value=vin;
document.getElementById("txtCopyVin").select();
}else{
rows[i].style.backgroundColor="white";
}
}
if(window.event!=null){
rows[rowNumber].cells(window.event.srcElement.cellIndex).focus();
}
}`
最佳答案
我刚刚通过自己的测试证实,这是 Microsoft 似乎在 IE10 中所做的更改,以使其与市场上所有其他浏览器兼容。在其他浏览器中,ID 和名称是不同的。但在 IE 10 之前,微软选择以不同的方式做事,这导致了很多不兼容性,如here所述。 。此更改修复了我为 chrome 编写的代码,但似乎破坏了为 IE 编写的代码。
如果您指示用户打开“兼容模式”,它应该像以前一样工作,但这可能不是一个好的长期解决方案。
好消息是,如果您在代码中通过使 id 引用 id 和名称引用名称来解决并解决此问题,您的网站将与 IE 之外的其他浏览器兼容。
查看您的代码,您似乎想将 id="resultRow"替换为 name="resultRow"
关于javascript - IE10 : getElementsByName() is not returning the elements that has same Id in IE10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16322770/