我是否可以使用一些jquery,在其中我可以在一行中更改css属性,更像这样
$("#box").css("height":"40px",
"width":"40px"
);
而不是像这样的两行代码?
$("#box").css("height","40px");
$("#box").css("width","40px");
发布于 2016-12-28 13:21:31
$('#box').css({
"height": "40px",
"width": "40px"
});
或者你可以尝试
$("#box").css("height","40px").css("width","40px");
发布于 2016-12-28 13:21:31
只需传递一个对象,您就可以更改任意数量的CSS属性
$("#box").css({
"height":"40px",
"width":"40px"
});
发布于 2016-12-28 13:24:51
最好的方法是在jquery中为元素id #box
使用.addClass()
方法。
$("#box").addClass("newclass");
在css中
.newclass {
height: 40px;
width: 40px;
}
https://stackoverflow.com/questions/41362987
复制相似问题