zoukankan      html  css  js  c++  java
  • Dom getElementsByTagName和getElementById

    1.DOM Core
    
    DOM Core 并不专属于JavaScript,任何一种支持DOM的程序设计语言都可以使用它。
    
    它的用途并非限于处理网页,也可以用来处理任何一种使用标记语言编写出来的文档,例如XML
    
    JavaScript 中的getElemntById(),getElementsByTagName()
    
    这些都是DOM Core的组成部分
    
    getElemntById()
    
    node2:/var/www/html/aa#cat a17.html 
    <html>  
    <body>  
    <div id='ID'>科技</div>  
    <script type="text/javascript" src="jquery-2.2.2.min.js"></script>  
    <script type="text/javascript" src="a17.js"></script>  
    </body>  
    </html> 
    
    node2:/var/www/html/aa#cat a17.js
    var domObj = document.getElementById("ID");//获得DOM对象  
    console.log(domObj);  
    var ObjHTML= domObj.innerHTML;  
    console.log(ObjHTML); 
    
    Navigated to http://192.168.137.3/aa/a17.html
    <div id="ID">
    a17.js:2:1
    科技
    
    [root@node01 tmp]# cat a17.html 
    <html>  
    <body>  
    <div id='ID'>科技</div>  
    <script type="text/javascript" src="jquery-2.2.2.min.js"></script>  
    <script type="text/javascript" src="a17.js"></script>  
    </body>  
    </html> 
    [root@node01 tmp]# cat a17.pl
    use LWP::UserAgent;      
    use POSIX;      
    use HTML::TreeBuilder::XPath;       
    use Encode;       
    use HTML::TreeBuilder;        
    use HTML::TreeBuilder::XPath;      
    use DBI;      
    use Encode;    
        my $tree= HTML::TreeBuilder::XPath->new;      
           $tree->parse_file("a17.html");    
             my @pageString = $tree->findvalues('//html/body/div[@id="ID"]');      
           print "@pageString is @pageString
    "; 
    [root@node01 tmp]# perl a17.pl
    @pageString is 科技
    
    
    
    
    node2:/var/www/html/aa#cat a17.js
    var domObj = document.getElementsByTagName("div")[0];//获得DOM对象  
    var ObjHTML= domObj.innerHTML;  
    console.log(ObjHTML);  
    
    Navigated to http://192.168.137.3/aa/a17.html
    科技
    
    
    科技[root@node01 tmp]# cat a18.pl 
    use LWP::UserAgent;      
    use POSIX;      
    use HTML::TreeBuilder::XPath;       
    use Encode;       
    use HTML::TreeBuilder;        
    use Data::Dumper;    
    use HTML::TreeBuilder::XPath;      
    use DBI;      
    use Encode;    
        my $tree= HTML::TreeBuilder::XPath->new;      
           $tree->parse_file("a17.html");    
           my @pageString = $tree->findvalues('//div');    
           print @pageString
    [root@node01 tmp]# perl a18.pl 
    科技[root@node01 tmp]# 
    

  • 相关阅读:
    POJ 1182 食物链
    HDU 1385 Minimum Transport Cost
    HDU_2544 最短路
    HDU 2066 一个人的旅行
    poj3090
    poj3157
    poj3169
    poj3125
    poj3187
    VMware Workstation 8的简明使用教程
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349298.html
Copyright © 2011-2022 走看看