欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js 根据td节点获取tr节点,及其他td节点的内容,兼容IE、FF、Chrome

程序员文章站 2022-05-25 22:32:15
...

html:

<tr class="bg_light" >
       <td style="height:30px" align="center" class="lockX">TTTTTT</td>
       <td align="center" class="lockX">
  TTTTTTTTTTTTTTTTT
       </td>
       <td style="text-align:left" class="lockX">&nbsp;TTTTTTTT&nbsp;</td>
       <td style="text-align:left" class="lockX">&nbsp;TTTTTTTTTT&nbsp;</td>
       <td style="text-align:left" class="unlock">&nbsp;TTTTTTTTTTT&nbsp;</td>
       <td style="text-align:left" class="unlock">&nbsp;TTTTTTTT&nbsp;</td>
       <td align="center" class="unlock">TTTTTTTTT&nbsp;</td>
       <td align="center" class="unlock">TTTTTTT&nbsp;</td>
       <td align="center" class="unlock">TTTTTTTT</td>
       <td align="center" class="unlock"><%=AVO.getRemark()%>&nbsp;</td>
       <td align="center" class="unlock">
  <a onmouseover="javascript:showTargetSys(this)">查看</a>
       </td>
       <td align="center" class="unlock">
  TTT
       </td>
 </tr>

 

javascript:

function showTargetSys(obj) {
 var trNodes = obj.parentNode.parentNode;
 var tdNodes = trNodes.childNodes;
 var tdNodesArray = new Array();
 for(var i = 0; i < tdNodes.length; i++) {
  var node = "";
  //IE下tagName能识别
  //FF、Chrome下tagName不能识别
  if(document.all) { //IE
   node = tdNodes[i].tagName;
  } else { //非IE
   node = tdNodes[i].nodeName;
  }
  if(node.toUpperCase() == "TD") {
   tdNodesArray.push(tdNodes[i]);
  }
 }
 var serviceMark = "";
 var methodMark = "";
 //IE下innerText能识别
 //FF、Chrome下innerText不能识别
 if(document.all) {
  serviceMark = tdNodesArray[4].innerText;
  methodMark = tdNodesArray[5].innerText;
 } else {
  serviceMark = tdNodesArray[4].textContent;
  methodMark = tdNodesArray[5].innerText;
 }
 
 var random = Math.random();//随机数,只传参,后台不用接收
 var url = "<%=contextPath%>/servlet/AjaxServlet?flag=getTargetSys&serviceId="+serviceId+"&methodId="+methodId+"&random"+random;
 
 $.get(
   url,
   function(response) {
    /*$('#targetSys').html(response);*/
    alert("response: " + response);
   });
 
 
 /*$('#targetSys').css('display', 'block');*/
}