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

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

css( properties ) - 语法

selector.css( properties )

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

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

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

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

css( properties ) - 示例

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


   
      </span><span class="pln">The jQuery Example</span><span class="tag">
       type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      
		
       type="text/javascript" language="javascript">
         $(document).ready(function() {
			
            $("div").click(function () {
               var color=$(this).css("background-color");
               $("#result").html("That div is " + color + ".");
               $("#result").css({color: yellow, font-weight : bold, 
                  background-color: gray});
            });
				
         });
      
		
      
   
	
   
      

Click on any square:

id="result"> style="background-color:blue;">
style="background-color:rgb(15,99,30);">
style="background-color:#123456;">
style="background-color:#f11;">

这将产生以下输出-

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

你可能感兴趣的:(无涯教程,jquery)