分类: 系统运维
2010-05-31 18:17:43
jquery动态创建页面元素,mark一下,以备以后查询时使用。
以创建div和input为例。
动态创建div:
01 |
$(function(){ |
02 |
$(" |
03 |
id: 'test', |
04 |
text: 'this is a test', |
05 |
"class": "test", |
06 |
click: function(){ |
07 |
$(this).toggleClass('test'); |
08 |
} |
09 |
}).appendTo("body"); |
10 |
}) |
动态创建input:
01 |
[/javascript] |
02 |
$(function(){ |
03 |
$("", { |
04 |
type: 'text', |
05 |
val: 'test', |
06 |
focusin: function() { |
07 |
$(this).addClass('active'); |
08 |
}, |
09 |
focusout: function() { |
10 |
$(this).removeClass('active'); |
11 |
} |
12 |
}).appendTo("body"); |
13 |
}) |
14 |
[javascript] |