简体   繁体   English

JQuery .append() - 元素失去样式

[英]JQuery .append() - elements lose styling

I'm attempting to add elements to a div container however the elements ignore their css class.我正在尝试将元素添加到 div 容器,但是这些元素忽略了它们的 css 类。

JavaScript JavaScript

$.each(jobs, function(i, job) 
{
    var option = '<div class="input"><div class="option">' + job.created +'</div></div>';
                    
    $('.options').append(option);
});

Html html

<div class="options" style="overflow: scroll; width: 100%; height: 80%; background-color: White; text-align: left;">
   <div class="input">
        <div class="option">
             Hunt Osama.
        </div>
        </div>
   <div class="input">
        <div class="option">
             Execute without trial.
        </div>
   </div>
</div>

The elements are successfully appended to the div however the styling information is not acted upon.元素已成功附加到 div,但不会对样式信息进行处理。

EDIT: the classes input and option have no effect on the added elements.编辑:类输入和选项对添加的元素没有影响。

Any hints?任何提示?

I have tested your code on my machine and it works fine in IE & Firefox if I apply CSS to the children.我已经在我的机器上测试了你的代码,如果我将 CSS 应用于孩子,它在 IE 和 Firefox 中运行良好。

In my css file I have added the following declaration:在我的 css 文件中,我添加了以下声明:

.option
{
    font-weight:bold !important;
    color: red;
}

This issue ended up being specific to WebKit/Qt on the windows mobile platform.此问题最终特定于 Windows 移动平台上的 WebKit/Qt。 It doesn't appear during a Android/WebKit example.它不会出现在 Android/WebKit 示例中。

Sorry I have no further details on the cause of the problem.抱歉,我没有关于问题原因的更多详细信息。

Thanks for all the help.感谢所有的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM