【问题标题】:How to fix issue HTML1402 with jquery url in IE?如何在 IE 中使用 jquery url 修复问题 HTML1402?
【发布时间】:2017-04-11 16:35:51
【问题描述】:

我真的不明白为什么 IE(仅适用于任何其他浏览器都可以)给我 HTML1402:字符引用缺少结束分号“;”,代码如下:

<!DOCTYPE HTML>
<html>
        <head>
                <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
        </head>
        <body>
                <span id="here"></span>
                <div id="url_iframe">https://www.google.com.br/search?q=ie+html+1402+with+jquery&ie=utf-8&oe=utf-8&client=firefox-b&gws_rd=cr</div>

        <script>
                var url_iframe = jQuery('#url_iframe').text();
                jQuery('#here').append('<iframe src="'+encodeURIComponent(url_iframe)+'" scrolling="no" frameborder="0" width="320" height="300"></iframe>');
        </script>
        </body>
</html>

有人知道如何修复它,以便停止出现在控制台中?

我试过没有 encodeURIComponent 和同样的错误。

该 URL 只是一个示例,我知道这不起作用,这是对一个非常大而复杂的代码问题的测试,我发现的只是如果我将其更改为 iframe 而不是使用 jquery,则没有警告显示,但我需要用 jquery 来做,因为我在真正的 web 应用程序中追加之前的数据。

【问题讨论】:

  • 您可以尝试在 iframe 的 js 字符串中转义()双引号。 '
  • 这就是为什么我写了“URL 只是一个示例,我知道这不起作用”,如果你在代码中看到它已经带有双引号,这就是我在其中使用单引号的原因jQuery.

标签: javascript jquery internet-explorer console


【解决方案1】:

假设错误必须是 MS 错误,我发现我是对的,我所需要的只是将 div 交换为输入:

<!DOCTYPE HTML>
<html>
        <head>
                <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
        </head>
        <body>
                <span id="here"></span>
                <input type="hidden" id="url_iframe" value="https://www.google.com.br/search?q=ie+html+1402+with+jquery&ie=utf-8&oe=utf-8&client=firefox-b&gws_rd=cr"/>

        <script>
                var url_iframe = jQuery('#url_iframe').val();
                jQuery('#here').append('<iframe src="'+url_iframe+'" scrolling="no" frameborder="0" width="320" height="300"></iframe>');
        </script>
        </body>
</html> 

如果有人知道如何使用 div,我会很高兴在这里分享...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    相关资源
    最近更新 更多