×

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

作者:Terry2017.02.02来源:Web前端之家浏览:9304评论:0
关键词:JQueryJS
动态创建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");
})

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1485964800714.html

网友评论文明上网理性发言已有0人参与

发表评论: