开发者

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

开发者 https://www.devze.com 2023-02-28 09:25 出处:网络
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}\");

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

精彩评论

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