如何使用相同的CSS属性而不使用jquery覆盖和多次?
$(function() {
$("#hello").css({
// Is there a way to apply both of these instead of having the second override the first?
"background-image" : "-webkit-gradient(linear,left top,left bottom,color-stop(0, #444444),color-stop(1, #999999))",
"background-image" : "-moz-linear-gradient(top, #444444, #999999)"
});
});
答案 0 :(得分:6)
将每个'指令'与;
分开。
$("#hello").css({
"background-image" : "-webkit-gradient(linear,left top,left bottom,color-stop(0, #444444),color-stop(1, #999999));-moz-linear-gradient(top, #444444, #999999)"
});
或者,将它放入一个CSS类中,并以更漂亮和易于管理的方式执行:
.gradient {
-webkit-gradient(linear,left top,left bottom,color-stop(0, #444444),color-stop(1, #999999));
-moz-linear-gradient(top, #444444, #999999);
}
$("#hello").addClass("gradient");