zoukankan      html  css  js  c++  java
  • 根据给定的id匹配一个元素

    node2:/var/www/html/jquery#cat a11.html 
    <html>
    <body>
    <div class="one" id="one">id为one,class为one的div</div>
    <div class="twozhaoyangjian" id="two">id为two,class为two的div</div>
    <div class="mini">class为mimi</div>  
    </body>
    <script type="text/javascript" src="jquery-2.2.2.min.js"></script>
    <script type="text/javascript" src="a11.js"></script>
    </html>
    
    
    node2:/var/www/html/jquery#cat a11.js 
    var item=$("#two");//获取id为tn的元素(table);
    console.log(item);
    You have mail in /var/spool/mail/root
    
    或者id等于two的元素
    
    [root@node01 jquery]# cat data.html 
    <html>
    <body>
    <div class="one" id="one">id为one,class为one的div</div>
    <div class="twozhaoyangjian" id="two">id为two,class为two的div</div>
    <div class="twozhaoyangjian" id="three">id为two,class为two的div</div>
    <div class="mini">class为mimi</div>  
    </body>
    <script type="text/javascript" src="jquery-2.2.2.min.js"></script>
    <script type="text/javascript" src="a11.js"></script>
    </html>
    [root@node01 jquery]# cat a2.pl 
    use  LWP::UserAgent;
    use DBI;  
    use POSIX;
    use Data::Dumper;
    use HTML::TreeBuilder;
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
    
    
      use HTML::TreeBuilder::XPath;
       $tree= HTML::TreeBuilder::XPath->new;
      $tree->parse_file( "data.html");
    my    @pages=$tree->find_by_tag_name('div');
                          #@urlall除了包含每个类别的文章,还包含阅读排行里的文章
                          foreach (@pages) {
                                                   @titlepage = $_->attr('id');
                                                   foreach (@titlepage) {
                                                     if ($_){ 
                                                    print "$_ is $_
    ";
                                                         };
                                               };
    };
    [root@node01 jquery]# perl a2.pl 
    $_ is one
    $_ is two
    $_ is three
    

  • 相关阅读:
    数据库操作
    用php输出心形曲线
    Hibernate入门(一)
    JavaScript中的三种弹窗
    java过滤器(过滤器排序)
    java过滤器(简化认证)
    Mysql中的外键分析(什么是外键,为什么要用外键,添加外键,主外键关联删除)
    java回调函数学习
    继承
    多态(一)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349322.html
Copyright © 2011-2022 走看看