修改样式属性
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> Document</ title>
< style>
div {
width : 200px;
height : 200px;
background-color : skyblue;
}
</ style>
< script src = " ./jquery .min.js" > </ script>
</ head>
< body>
< div> </ div>
< script>
$ ( function ( ) {
console. log ( $ ( 'div' ) . css ( "width" ) ) ;
$ ( 'div' ) . css ( { width: 400 , height: 400 , backgroundColor: "red" } ) ;
} )
</ script>
</ body>
</ html>
设置类方式
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> Document</ title>
< script src = " ./jquery .min.js" > </ script>
< style>
div {
width : 200px;
height : 200px;
background-color : skyblue;
transition : all 0.5s;
}
.red {
background-color : red;
}
.circle {
border-radius : 60px;
}
.current {
transform : rotate ( 70deg) ;
}
</ style>
</ head>
< body>
< div class = " circle" > 1</ div>
< script>
$ ( function ( ) {
$ ( 'div' ) . click ( function ( ) {
$ ( this ) . addClass ( "red" ) ;
} )
$ ( "div" ) . mouseover ( function ( ) {
$ ( this ) . removeClass ( "circle" ) ;
} )
$ ( "div" ) . click ( function ( ) {
$ ( this ) . toggleClass ( "current" ) ;
} )
} )
</ script>
</ body>
</ html>