简体   繁体   English

CSS不适用于Javascript创建的元素

[英]CSS not applying on Javascript created element

I insert fields on my page using the JQuery .html() function. 我使用JQuery .html()函数在页面上插入字段。 The fields have a class attribute, but it seems like the CSS, which is declared in the header part of the page doesn't apply to the element. 这些字段具有class属性,但是好像在页面标题部分中声明的CSS不适用于该元素。

I believe it just impact class selector, since I have a #editZone input selector that work like a charm. 我相信这只会影响类选择器,因为我有一个像###########################################

Here's a code sample: 这是一个代码示例:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<style type="text/css">
    #editZone input, #editZone textarea, #editZone select{
        border:0px;
    }

    #editZone .dependant {
        background-color:#CCC;
        border-bottom:1px solid #333;
    }
    #editZone .original {
        background-color:#FFF;
        border-bottom:1px solid #300;
    }
</style>

</head>
<body>

    <div id="headZone">
        Template:
        <select id="template">
        </select>
        <input type="button" id="generateTpl" value="Go" />
    </div>
    <div id="editZone" style="background-color:#ccc;">content will be filled here upon template selection</div>
    <div id="previewZone">final</div>
</body>
</html>

Here's a content sample (from firebug): 这是内容示例(来自Firebug):

<div style="background-color:#ccc;" id="editZone"><br>
<br>
Name - <input type="" class="original" value="" name="first_name" id="first_name_1"> <input type="" class="original" value="" name="last_name" id="last_name_1"><br>
Title<br>
...

You should close the html tags and I think it should work then. 您应该关闭html标签,然后我认为它应该可以工作。 Close the tags like "<tagname />" or "<tagname></tagname>" . 关闭"<tagname />""<tagname></tagname>"类的标签。 I mean input, br and all the opened tags are not closed. 我的意思是输入,br和所有打开的标签都没有关闭。

Hope it helps. 希望能帮助到你。

Cheers 干杯

在样式声明中,我在类名和{之间有一个奇怪的空格。

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

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