Home  >  Article  >  Web Front-end  >  基于Jquery的动态创建DOM元素的代码_jquery

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

WBOY
WBOYOriginal
2016-05-16 18:13:14899browse

动态创建div:

复制代码 代码如下:

$(function(){
$("
",{
id: 'test',
text: 'this is a test',
"class": "test",
click: function(){
$(this).toggleClass('test');
}
}).appendTo("body");
})

动态创建input:
复制代码 代码如下:

$(function(){
$("", {
type: 'text',
val: 'test',
focusin: function() {
$(this).addClass('active');
},
focusout: function() {
$(this).removeClass('active');
}
}).appendTo("body");
})
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn