我有一个 DIV,它是通过 jQuery 对 perl 脚本的 ajax 调用编写的 - 然后在成功时使用 .html() 编写
编写的 html 包含多个 DIV ...每个 DIV 都有一个 ID 和一个用于样式的 css 文件中的条目。
我遇到的问题是在编写文本时会忽略样式。
例子:
HTML:
<link rel="stylesheet" type="text/css" href="layout.css" />
...
<div id="CONTAINER"></div>
javascript:
$.ajax({
url: './GetInfo.pl',
success: function(data) {
alert(data); // to check the right html is returned - and it is!
$('#CONTAINER').html(data);
}
});
CSS:
body { color: black; font-size: 10pt; }
#childDiv1 { color: #ffffff; font-size: 12pt; }
#childDiv2 { color: #ffff00; font-size: 14pt; }
#childDiv3 { color: #ff00ff; font-size: 16pt; }
珀尔:
print <<HTML;
Content-type: text/html
<div id="childDiv1">Info 1</div>
<div id="childDiv2">Info 2</div>
<div id="childDiv3">Info 3</div>
HTML
....所有 DIV 都有正确的文本,但样式取自 CSS 文件中的 BODY 条目,而不是新的 DIV 条目。