Home  >  Article  >  Web Front-end  >  Use of parsing the children object array elements firstChild and lastChild in dom_javascript skills

Use of parsing the children object array elements firstChild and lastChild in dom_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:29:241059browse

Copy code The code is as follows:




    
  行1列1 行1列2   
  行2列1 行2列2
 
    
    
    
 
    
    
 
  
 
  

  <script>   <br>  alert(test.children[0].tagName)   <br>  alert(test.children[1].tagName)   <br>  </script>  


document.all.tbl.children(0).children(0).innerHTML解释
document.all.tbl.children(0)定位到table的第一个子节点
document.all.tbl.children(0).children(0)定位到table的第一个子节点的第一个子节点,打印结果 行1列1 行1列2


document.all.tbl.children(0).children(1).innerHTML,打印结果 行2列1 行2列2


document.all.tbl.children(0).children(1).children(0).innerHTML 打印结果行2列2





    
  行1列1 行1列2   
  行2列1 行2列2
 
    
    
    
 
    
    
 

  
 
  

  <script>   <br>  alert(test.firstChild.tagName)   <br>  alert(test.lastChild.tagName)   <br>  </script>  


document.all.tbl.firstChild定位到table的第一个子节点
document.all.tbl.firstChild.firstChild定位到table的第一个子节点
的第一个子节点
document.all.tbl.firstChild.firstChild.innerHTML打印结果是 行1列1 行1列2


document.all.tbl.firstChild.lastChild定位到table的第一个子节点
的最后子节点
document.all.tbl.firstChild.lastChild.innerHTML打印结果是 行2列1 行2列2


document.all.tbl.firstChild.lastChild.firstChild.innerHTML 打印结果是
行2列2

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Methods and ideas for simulating class mechanisms and private variables in JavaScript_javascript skillsNext article:Methods and ideas for simulating class mechanisms and private variables in JavaScript_javascript skills

Related articles

See more