• 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]# 
    

  • 相关阅读:
    sql server 分析
    3月5日总结
    sql server sql语句
    sql server数据类型char和nchar,varchar和nvarchar,text和ntext
    GIT 查看/修改用户名和邮箱地址
    Ubuntu安装LAMP环境(PHP5.6) 以及下载安装phpmyadmin
    Windows 10和Ubuntu 16.04双系统时间错误的调整
    php定界符<<<EOF讲解(转)
    matlab示例程序--Motion-Based Multiple Object Tracking--卡尔曼多目标跟踪程序--解读
    sa分析
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349298.html
Copyright © 2020-2023  润新知