基于Jquery的动态创建DOM元素的代码
作者:Terry2017.02.02来源:Web前端之家浏览:11113评论:0
动态创建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人参与
发表评论: