【问题标题】:How to style the dynamically created html elemnts through jquery如何通过jquery对动态创建的html元素进行样式设置
【发布时间】:2012-11-10 10:26:24
【问题描述】:

我已经创建了如下所示的脚本:

 $.getJSON('Json.json',function(data){
 $('#output').empty();                          
 var html = '<div class="general">';                    
 html += '<span class="logo">' + data.general.logo+ '</span>';
 html += '<span class="name">' + data.general.name+ '</span>';
 html += '</div>';  
 html +='<ul class="navigation" >'; 
 html +='<li><a href='+data.navigation[0].link+'>'+data.navigation[0].title+'</a></li>'; 

我的问题是我现在如何在 CSS 中设置这些类的样式。我也将如何获取 ids,因为目前我将 id 值作为 data.x.id smthing 像这样。

【问题讨论】:

    标签: css styles


    【解决方案1】:

    当您在旅途中创建元素时,您必须使用.on() 方法。 http://api.jquery.com/on/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 2019-10-26
      • 1970-01-01
      相关资源
      最近更新 更多