jquery動態(tài)創(chuàng)建頁面元素,mark一下,以備以后查詢時使用。以創(chuàng)建div和input為例。
動態(tài)創(chuàng)建div:
$(function(){ $("<div>",{ id: 'test', text: 'this is a test', "class": "test", click: function(){ $(this).toggleClass('test'); } }).appendTo("body"); })
動態(tài)創(chuàng)建input:
$(function(){ $("<input>", { type: 'text', val: 'test', focusin: function() { $(this).addClass('active'); }, focusout: function() { $(this).removeClass('active'); } }).appendTo("body"); })
新聞熱點
疑難解答
圖片精選