开发者

create style element, define some classes and add class to element

is there any better way?

$("< style >").attr("t开发者_运维知识库ype","text/css").prependTo("head").append(".bor {border:2px dotted red} .gto {padding:10px; font-size:medium}");

$("input:text").addClass("bor gto").val("your text");

http://jsfiddle.net/adatepe/aLmc2/


Maybe you could set the CSS directly rather than trying to build CSS classes at runtime:

$('input:text').css({
    border: '2px dotted red',
    padding: '10px',
    fontSize: 'medium'
}).val('your text');


If by any chance you need to do this way why not do it the simple way then?

$("<style type='text/css'>.bor {border:2px dotted red}" + 
  " .gto {padding:10px; font-size:medium}</style>").prependTo("head");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜