Jquery动态创建DOM元素
时间:2010-05-31 来源:xue2
Jquery动态创建DOM元素
jquery动态创建页面元素,mark一下,以备以后查询时使用。
以创建div和input为例。
动态创建div:
01 | $(function(){ |
02 | $("<div>",{ |
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 | $("<input>", { |
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] |
您可以任意转载本文,但转载时请以超链接形式标明文章原始出处和作者信息及版权声明
作者:muxi,原文链接:http://muxi.me/jquery/jquery%e5%8a%a8%e6%80%81%e5%88%9b%e5%bb%badom%e5%85%83%e7%b4%a0.html
作者:muxi,原文链接:http://muxi.me/jquery/jquery%e5%8a%a8%e6%80%81%e5%88%9b%e5%bb%badom%e5%85%83%e7%b4%a0.html
相关阅读 更多 +