zoukankan      html  css  js  c++  java
  • 1.查找元素节点

    1.查找元素节点
    
    获取元素节点并打印出它的文本内容,jQuery代码如下:
    
    node2:/var/www/html/aa#cat a18.html 
    <html>
    <head>
    <title>dom</title>
    </head>
    <body>
       <p title="选择你最喜欢的水果.">你最喜欢的水果是?</p>
    <ul>
    <li title='苹果'>苹果</li>
    <li title='橘子'>橘子</li>
    <li title='菠萝'>菠萝</li>
    </body>
    </html>
    <script type="text/javascript" src="jquery-2.2.2.min.js"></script>
    <script type="text/javascript" src="a18.js"></script>
    
    
    node2:/var/www/html/aa#cat a18.js
    var $li =$("ul li:eq(1)"); //获取<ul>里的第2个<li>节点
    console.log($li);
    
    
    Navigated to http://192.168.137.3/aa/a18.html
    {…}
    0: <li title="橘子">
    context: HTMLDocument http://192.168.137.3/aa/a18.html
    length: 1
    prevObject: Object { 0: HTMLDocument http://192.168.137.3/aa/a18.html, context: HTMLDocument http://192.168.137.3/aa/a18.html, length: 1 }
    selector: "ul li:eq(1)"
    __proto__: Object { jquery: "2.2.2", constructor: n(), length: 0, … }
    
    
    node2:/var/www/html/aa#cat a18.js
    var $li =$("ul li:eq(1)"); //获取<ul>里的第2个<li>节点
    var li_txt=$li.text();//获取第2个<li>元素节点的文本内容
    console.log(li_txt);
    
    
    Navigated to http://192.168.137.3/aa/a18.html
    橘子

  • 相关阅读:
    oracle行转列
    JVM设置空间大小
    Spring AOP 业务权限管理
    清晨漫步
    pull解析xml(android)
    今昔何昔
    Spring: Document root element "beans", must match DOCTYPE root "null
    xfire
    心之所向
    Oracle数据库连接
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349297.html
Copyright © 2011-2022 走看看