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

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

2018-10-12 14:03 756 查看
动态创建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");
})

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: