jquery 如何修改css样式
时间: 2023-11-28 07:05:55 浏览: 137
使用 jQuery 的 css() 方法可以修改 CSS 样式。
语法:
```javascript
$(selector).css(property,value)
```
示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>jQuery 修改 CSS 样式</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
#box {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div id="box"></div>
<button id="btn">修改样式</button>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#box").css("background-color", "blue");
$("#box").css("width", "300px");
$("#box").css("height", "300px");
});
});
</script>
</body>
</html>
```
在上面的示例中,当点击“修改样式”按钮时,会通过 jQuery 的 css() 方法修改 #box 元素的背景颜色、宽度和高度。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)