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");
})

直接append

$("p").append("<b>Hello</b>");

也可以先append再addClass

 


相关文章:

  • 2021-09-17
  • 2022-01-14
  • 2022-02-09
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-07
  • 2021-10-20
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案