无涯教程-jQuery - css( properties )方法函数

css(properties)方法将键/值对象设置为所有匹配元素的样式属性。

css( properties ) - 语法

selector.css( properties )

上面的语法可以写成如下-

selector.css( {
   
   key1:val1, key2:val2....keyN:valN})

这是此方法使用的所有参数的描述-

  • key:value      -  设置为样式属性的键/值对。

css( properties ) - 示例

以下是一个简单的示例,简单说明了此方法的用法-

<html>
   <head>
      <title>The jQuery Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
   
   
			
            $("div").click(function () {
   
   
               var color=$(this).css("background-color");
               $("#result").html("That div is <span>" + color + "</span>.");
               $("#result").css({
   
   color: yellow, font-weight : bold, 
                  background-color: gray});
            });
				
         });
      </script>
		
      <style>
         div {
   
    width:60px; height:60px; margin:5px; float:left; }
      </style>
   </head>
	
   <body>
      <p>Click on any square:</p>
      <span id="result"> </span>
		
      <div style="background-color:blue;"></div>
      <div style="background-color:rgb(15,99,30);"></div>
      <div style="background-color:#123456;"></div>
      <div style="background-color:#f11;"></div>
   </body>
</html>

这将产生以下输出-

jQuery 中的 css( properties )方法函 - 无涯教程网无涯教程网提供css(properties)方法将键/值对象设置为所有匹配元素的样式属性。 css( properties ) -...https://www.learnfk.com/jquery/css-properties.html

猜你喜欢

转载自blog.csdn.net/w116858389/article/details/132020254