文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Jquery动态创建DOM元素

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
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载