Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:29:24
Original
1112 people have browsed it

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

Related labels:
source:php.cn
Previous article:Methods and ideas for simulating class mechanisms and private variables in JavaScript_javascript skills Next article:js fixed DIV height, a simple way to automatically add scroll bars beyond the part_javascript skills
Statement of this Website
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
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template