我正在使用 AJAX 从数据库中获取特定页面的页面内容。 这很完美,但现在我的问题是:
对于“联系”页面,我从数据库中获取了一个表单(只是 HTML...)。但它忽略了 CSS,我已经加载到页面的头部。 表单部件具有 ID 和类。
我的想法是,它是由我加载 CSS 之后插入内容引起的。
注意:我没有使用 JQuery,也不想在这个元素中使用它。
表单如下所示:
<form method="post" action="#">
<label id="CLabel" for="sendname">Name:<span class="required"></span></label><input type="text" class="contact" name="sendname" maxlength="30" required placeholder="Your Name..(Required)"><br>
<label id="CLabel" for="sendemail">Email:<span class="required"></span></label><input type="email" class="contact" name="sendemail" maxlength="100" placeholder="Your Email-address.."><br>
<label id="CLabel" for="reason">Contact reason:</label><input type="text" class="contact" name="sendreason" maxlength="30" required placeholder="Your Reason..(Required)"><br>
<label id="CLabel" for="sendmsg"></label><textarea id="cmsg" class="noResize" name="sendmsg" required placeholder="Your Message..(Required)" onfocus="this.value=\"\"; this.onfocus=null;"></textarea><br>
<label id="CLabel" for="contactbutton"></label><input class="contactbutton" type="submit" name="contactbutton" value="Send">
</form>
要查看 CSS 或 Javascript,请查看链接: philliprohde.bugs3.com/new_/
CSS 如下(将 id 更改为类):
label.CLabel{
display:inline-block;
width: 7em;
}
input.contact{
width:400px;
margin-top:5px;
}
/* Button of the contact form */
.contactbutton{
width: 100px;
background: #c1c1c1;
color: #8b0000;
text-transform: uppercase;
text-shadow: #000 1px 1px;
margin-top: 10px;
}
textarea.noResize { resize:none; }
textarea#cmsg {
width: 400px;
height: 120px;
margin-top:5px;
border:none;
font-family: Tahoma, sans-serif;
}
已解决。托管商没有接受我的新 css 文件(我不知道为什么)。 我删除了旧的,重新上传了,现在可以用了。
感谢您的支持!
最佳答案
两件事:
- 您的预览链接无效;
- 您发布的标记无效(您正在为您的标签重复使用 ID“CLabel”)。
尽管多 ID 可能会在开发的其他地方为您带来一些问题,但这些都不会影响您的 CSS。
加载后将内容添加到页面中将由您在页面中获得的任何 CSS 设置样式(相关)。
以下是我建议您进行调试的内容:
- 有没有可能 CSS 并没有像您预期的那样被包含在内?打开 Firebug 或 Chrome 开发者工具,确保您在 CSS 通过时没有遇到任何错误。
- 您的 CSS 是否可能没有正确定位新内容?
- (目前)从您的问题中看不出来,但您是否有可能通过 iFrame 加载内容(在这种情况下,父页面的 CSS 不会影响它)。
关于php - 使用 AJAX 插入后,HTML 内容不应用 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16540669/