2011-04-05 34 views
2

我有一个jQuery脚本的问题。我添加了一个新的DIV到函数附加的其他DIV中,但CSS样式不选择已声明的DIV类。添加DIV附加,但没有CSS样式

例如:

<style"> 
    .example { background-color:#00000; } 
</style> 

$('#test).append('<div class="example"></div>'); 

我装入样式表:

<link rel="stylesheet" type="text/css" href="./css/example.css"> 
+4

你的例子,缺少报价和零抛开,应该工作。 CSS不接受五位数的颜色代码。 – Amadan 2011-04-05 08:09:22

+1

尝试firebug http://getfirebug.com/来调试所有这些问题。 – yogs 2011-04-05 08:15:09

+0

Amadan指出您的颜色代码不正确 – techfoobar 2011-12-23 10:00:26

回答

2

你可以尝试以下方法:

$('#test').append($('<div></div>').attr('class', 'example')); 

或者

$('#test').html('<div class="example"></div>');