style也可以看做普通的HTML节点,因此其创建方法与jQuery创建普通元素的方法相同,关键代码:
$("").text("div#test{color:red;}").appendTo($("head"));
下面实例演示——点击按钮创建新的style样式:
1、HTML结构
这是示例的DIV
">
2、jQuery代码
$(function(){
$("input[type='button']").click(function() {
$("").text("div#test{color:red;}").appendTo($("head"));
$("div#test").html($("div#test").text() + "
" + $("#test_style").text());
});
});
3、效果演示
$('