zoukankan      html  css  js  c++  java
  • JQuery之CSS函数

    jQuery 拥有三种用于 CSS 操作的重要函数:

    •      $(selector).css(name,value)
    •      $(selector).css({properties})
    •      $(selector).css(name)

     $(selector).css(name,value)用法示例:为所有匹配元素的给定 CSS 属性设置值

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        $("p").css("background-color","red");
      });
    });
    </script>
    </head>

    <body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click me</button>
    </body>
    </html>  


    $(selector).css({properties}) 用法示例:同时为所有匹配元素的一系列 CSS 属性设置值

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        $("p").css({"background-color":"red","font-size":"200%"});
      });
    });
    </script>
    </head>

    <body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click me</button>
    </body>
    </html>

    $(selector).css(name) 用法示例:返回指定的 CSS 属性的值

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("div").click(function(){
      $("#result").html($(this).css("background-color"));
      });
    });
    </script>
    </head>

    <body>
    <div style="100px;height:100px;
    background:#ff0000"
    ></div>
    <id="result">Click in the box</p>
    </body>

    </html>   

  • 相关阅读:
    BUPT复试专题—最长连续等差子数列(2014软院)
    BUPT复试专题—奇偶求和(2014软件)
    BUPT复试专题—网络传输(2014网研)
    Hopscotch(POJ 3050 DFS)
    Backward Digit Sums(POJ 3187)
    Smallest Difference(POJ 2718)
    Meteor Shower(POJ 3669)
    Red and Black(poj 1979 bfs)
    测试
    Equations(hdu 1496 二分查找+各种剪枝)
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/2583712.html
Copyright © 2011-2022 走看看