要使用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://cdn.staticfile.org/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>