我正在尝试将padding-top
值添加到我在标头中附加的css中,但只有color
正在运行:
var PaddingTOp = $('#PaddingTOp').val();
var PaddingRight = $('#PaddingRight').val();
var PaddingBottom = $('#PaddingBottom').val();
var PaddingLeft = $('#PaddingLeft').val();
//Class Name
$("<style type='text/css'> .redbold{ color:#f00; padding-top: PaddingTOp ;} </style>").appendTo("head");
$(".container").addClass("redbold");
答案 0 :(得分:2)
$("<style type='text/css'> .redbold{ color:#f00; padding-top: "+PaddingTOp+" ;} </style>").appendTo("head");
答案 1 :(得分:0)
var PaddingTOp = $('#PaddingTOp').val();
var PaddingRight = $('#PaddingRight').val();
var PaddingBottom = $('#PaddingBottom').val();
var PaddingLeft = $('#PaddingLeft').val();
//Class Name
var cssToApply = "color:#f00;";
$.trim(PaddingTOp).length > 0 ? cssToApply + "padding-top:"+PaddingTOp +";" : "";
$.trim(PaddingRight ).length > 0 ? cssToApply + "padding-right:"+PaddingRight +";" : "";
$.trim(PaddingBottom ).length > 0 ? cssToApply + "padding-bottom:"+PaddingBottom +";" : "";
$.trim(PaddingLeft ).length > 0 ? cssToApply + "padding-left:"+PaddingLeft +";" : "";
$("<style type='text/css'> .redbold{ "+ cssToApply +"} </style>").appendTo("head");
$(".container").addClass("redbold");