我有一个未通过验证的对比度切换器。我已经阅读了When is a CDATA section necessary within a script tag?,并尝试转义字符和使用CDATA,但我仍然收到这两种情况的验证错误。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<script type="text/javascript">
$(document).ready(function(){
// DRY wrapper function
function appendStyleSheet() {
$('head').append('<link rel="stylesheet" href="{site_url}css/high-contrast.css" type="text/css" id="hc_stylesheet"/>');
}
// append the style sheet on load if the cookie is set to true
if ($.cookie('high_contrast_momentum') == 'true') {
appendStyleSheet();
}
$("#contrast-btn a").click(function () {
if ($.cookie('high_contrast_momentum') != 'true') {
appendStyleSheet();
$.cookie('high_contrast_momentum', 'true', {expires:365}); // set the cookie to true
}
else {
// remove the high-contrast style
$("#hc_stylesheet").remove();
$.cookie('high_contrast_momentum', 'false');
}
});
});
</script> 我得到的验证错误是:文档类型在这里不允许元素"link“
发布于 2012-08-03 19:04:07
允许在标记内使用标记,不允许在标记内使用标记。
另一方面,在您的标记中出现标记是一种简单的误解。xHTML文档(因为您使用的是xHTML DTD)确实包含CDATA部分,以确保脚本区的内容不会被解析为xHTML to。
您的错误是由使用xHTML保留字符&/引起的。
验证引擎可能错误地读取了脚本标记内的链接,即使这些脚本标记的内容不应该被解析为HTML。
尝试将较低的符号与字符串的其余部分分开,如下所示:
$('head').append('<'+'link rel="stylesheet" href="{site_url}css/high-contrast.css" type="text/css" id="hc_stylesheet"/'+'>'); https://stackoverflow.com/questions/11794411
复制相似问题