我使用 JQuery .html() 函数在页面上插入字段。这些字段有一个 class 属性,但页面标题部分中声明的 CSS 似乎不适用于该元素。
我相信它只会影响类选择器,因为我有一个像魅力一样工作的 #editZone 输入选择器。
这是一个代码示例:
<!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>
这是一个内容示例(来自 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>
...
最佳答案
你应该关闭 html 标签,我认为它应该可以工作。关闭标签,如 "<tagname />"
或"<tagname></tagname>"
。我的意思是 input、br 和所有打开的标签都没有关闭。
希望有帮助。
干杯
关于javascript - CSS 不适用于 Javascript 创建的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13424362/