如何使用 jQuery 應用 CSS 屬性?


如需使用 jQuery 應用 CSS 屬性,使用 css() 方法。使用 jQuery 方法 css( PropertyName, PropertyValue ) 輕鬆應用任何 CSS 屬性。

以下是方法語法 −

selector.css( PropertyName, PropertyValue );

示例

可以在此處將 PropertyName 作為 JavaScript 字串傳遞,根據其值,PropertyValue 可以是字串或整數。

線上演示

<html>

   <head>
      <title>jQuery css() method</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {
            $("li").eq(4).css("color", "green");
         });
      </script>
   </head>
   
   <body>
   
      <div>
         <ol>
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
            <li>list item 4</li>
            <li>list item 5</li>
            <li>list item 6</li>
         </ol>
      </div>
       
   </body>
</html>

更新日期:18-12-2019

768 次瀏覽

開啟 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.