Jquery的动态创建DOM元素
生活随笔
收集整理的這篇文章主要介紹了
Jquery的动态创建DOM元素
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jquery動態創建頁面元素,mark一下,以備以后查詢時使用。以創建div和input為例。
動態創建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"); })
動態創建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"); })
轉載于:https://blog.51cto.com/minren8/482111
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的Jquery的动态创建DOM元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决ubuntu上网慢
- 下一篇: 侠客博客v1.0 正式版版本发布