css(name,value)方法将单个样式属性设置为所有匹配元素上的值。
selector.css( name, value )
这是此方法使用的所有参数的描述-
name - 要设置的属性的名称。
value - 属性的值。
以下是一个简单的示例,简单说明了此方法的用法-
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/css-name-value.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", color); }); }); </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>
这将产生以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
HarmonyOS快速入门与实战 -〔QCon+案例研习社〕