jQuery之操作样式的css方法

时间:2022-10-17 21:25:52

注意点都在代码里

     <style>
div {
width: 200px;
height: 200px;
background-color: pink;
}
</style>
<div></div>
<script>
// 操作样式之css方法
$(function () {
console.log($("div").css("width"));
// $("div").css("width", "300px");
// $("div").css("width", 300);
// $("div").css(height, "300px"); 属性名一定要加引号
$("div").css({
width: 400,
height: 400,
backgroundColor: "red"
// 如果是复合属性则必须采取驼峰命名法,如果值不是数字,则需要加引号
})
})
</script>