您的位置:首页 > Web前端 > JQuery

基于Jquery的动态创建DOM元素的代码

2010-12-28 00:00 741 查看
动态创建div:
$(function(){ 
$("<div>",{ 
id: 'test', 
text: 'this is a test', 
"class": "test", 
click: function(){ 
$(this).toggleClass('test'); 
} 
}).appendTo("body"); 
})

动态创建input:
$(function(){ 
$("<input>", { 
type: 'text', 
val: 'test', 
focusin: function() { 
$(this).addClass('active'); 
}, 
focusout: function() { 
$(this).removeClass('active'); 
} 
}).appendTo("body"); 
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: