zoukankan      html  css  js  c++  java
  • jquery1.9学习笔记 之选择器(基本元素一)

    所有选择器("*")

     

    描述:选择所有元素

     

    注意:大多数情况下,这个选择器极其的慢,尤其是在作用于自身时。

     

    例子:

    查找文档中的每个元素。然后追加一个<script><link>元素到DOM里,

    这个元素会被认为是可行的。

     

    <!doctype html>

    <html lang="zh">

    <head>

    <meta charset="utf-8">

    <title>all demo</title>

    <style type="text/css">

    h3{

    margin:0;

    }

    div,span,p{

    80px;

    height:40px;

    float:left;

    padding:10px;

    margin:10px;

    background-color: #EEEEEE;

    }

    </style>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>

    </head>

    <body>

    <div>9999</div>

    <span>SPAN</span>

    <p>P<button>Button</button></p>

    <script>

    var elementCount = $("*").css("border", "3px solid red" ).length;

    $( "body" ).prepend("<h3>" + elementCount + " elements found</h3>" );

    </script>

    </body>

    </html>

     

     

    例子:查找document.body中的所有元素,但不包括head,script,etc 标签。

    <!doctype html>

    <html lang="zh">

    <head>

    <meta charset="utf-8">

    <title>all demo</title>

    <style type="text/css">

    h3{

    margin:0;

    }

    div,span,p{

    80px;

    height: 40px;

    float:left;

    padding: 10px;

    margin: 10px;

    background-color: #EEEEEE;

    }

    #test{

     auto;

    height: auto;

    background-color: transparent;

    }

    </style>

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

    </head>

    <body>

    <div id='test'>

    <div>DIV</div>

    <span>SPAN</span>

    <p>P<button>Button</button></p>

    </div>

    <script>

    var elementCount = $("#test").find("*").css("border", "3px solid red").length;

    $("body").prepend("<h3>"+ elementCount +" elements found</h3>");

    </script>

    </body>

    </html>

     

     

     

  • 相关阅读:
    Jquery 将表单序列化为Json对象
    Modify the server ports
    iOS开发
    Leetcode_num4_Reverse Integer
    hdu 5443 The Water Problem(长春网络赛——暴力)
    E-R图到数据库表
    iOS音频播放 (三):AudioFileStream 转
    JAVA基础之訪问控制权限(封装)
    多做善事,会得到好报的
    mac 安装软件提示权限不足的解决的方法
  • 原文地址:https://www.cnblogs.com/semcoding/p/3282215.html
Copyright © 2011-2022 走看看