【问题标题】:validation error with jquery append <link rel="stylesheet" to headjquery 的验证错误将 <link rel="stylesheet" 附加到头部
【发布时间】:2012-08-01 10:11:44
【问题描述】:

我有一个未通过验证的对比度切换器。我读过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>   

我得到的验证错误是:文档类型不允许此处的元素“链接”

【问题讨论】:

    标签: jquery append cdata styleswitching


    【解决方案1】:

    标签内可以使用标签,

    【讨论】:

    • 我添加时它不喜欢加号,有更多的验证错误,并且似乎从字面上对待加号。我认为它的解析很好。对比度切换器适用于上述代码。在我看来,阅读错误消息就像我不允许在这里使用 标记一样。不过我真的不明白为什么。
    猜你喜欢
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    相关资源
    最近更新 更多