jquery的css函数可以一次指定多个style属性吗?

html-css012

jquery的css函数可以一次指定多个style属性吗?,第1张

当然可以啦。Jquery里面很多参数都可以用json方式传值的。

如:

$("p").css({ "margin-left": "10px", "background-color": "blue" })

如果多个标签的style部分或完成相同可以用class来归类。如:

<div style='background-color: red top: 10px width: 10px height: 10px'></div>

<div style='background-color: blue top: 30px width: 10px height: 10px'></div>

<div style='background-color: green top: 50px width: 10px height: 10px'></div>

宽高相同,,那么就可以改为

<style type='text/css'>

    .style1 {width: 10px height: 10px}

</style>

<div class='style1' style='background-color: red top: 10px'></div>

<div class='style1' style='background-color: blue top: 30px'></div>

<div class='style1' style='background-color: green top: 50px'></div>