jQuery 中的 css( properties )方法函

首页 / jQuery入门教程 / jQuery 中的 css( properties )方法函

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

css( properties ) - 语法

selector.css( properties )

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

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

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

无涯教程网

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

css( properties ) - 示例

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

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/css-properties.html

来源:LearnFk无涯教程网

<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>

这将产生以下输出-

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

人工智能基础课 -〔王天一〕

程序员的数学基础课 -〔黄申〕

Vue开发实战 -〔唐金州〕

图解 Google V8 -〔李兵〕

Selenium自动化测试实战 -〔郭宏志〕

乔新亮的CTO成长复盘 -〔乔新亮〕

小马哥讲Spring AOP编程思想 -〔小马哥〕

零基础实战机器学习 -〔黄佳〕

超级访谈:对话毕玄 -〔毕玄〕

好记忆不如烂笔头。留下您的足迹吧 :)