代码之家  ›  专栏  ›  技术社区  ›  Omar Abid

动态创建元素的jquery css()。

  •  13
  • Omar Abid  · 技术社区  · 14 年前

    我正在使用jquery css函数设置某些元素的样式

    $element.css(style);
    

    这是可行的,但在页面加载之后会动态创建部分元素。 这应该是

    $element.live ('created',function() {
    $(this).css(style);
    });
    

    我被困在创建的事件上。有什么想法吗?

    2 回复  |  直到 10 年前
        1
  •  21
  •   Andy E    14 年前

    • $('<img id="createdImage" src="some.jpg"/>')
          .appendTo(document.body)
          .css(style);
      
    • $("<style>").text("#myNewEl { width:20px; height:30px; }").appendTo("head");
      
        2
  •  0
  •   Rizier123    10 年前
    $('head').append('
    < style >
    .folder { background: url(../icons/Folder_icons/g/f.png) no-repeat left top;} < / style >');