我在本地Windows开发环境中使用jquery UI选项卡。我在用他们的demo code测试
<div id="tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. </p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede ve</p>
</div>
</div>
问题是我在这个函数上得到了一个“未捕获的URIError: URI格式错误”:
function isLocal( anchor ) {
return anchor.hash.length > 1 &&
decodeURIComponent( anchor.href.replace( rhash, "" ) ) ===
Uncaught URIError: URI malformed
decodeURIComponent( location.href.replace( rhash, "" ) );
}
我怀疑这是因为windows环境中的URI如下所示:
file:///C:/Work/my%20project/yadda%20ac%E7%F5es%20yadda/submenu.html#tabs-1
我怎么能让它在本地Windows上工作,因为我的客户希望在上线之前看到它在本地Windows上工作?我已经测试过了,我知道这是由uri上的特殊字符编码引起的(就像单词“acçóes”一样)。有没有办法让它在处理特殊字符时也能正常工作呢?
我知道我可以简单地通过删除这些字符并重命名文件/文件夹来解决这个问题,但我希望有一个更适合客户的解决方案,以防他们决定再次重命名文件夹(而且所有内容都在他们的脸上CABOOM )。
发布于 2014-01-13 03:06:09
这是非utf8URL的jquery - http://bugs.jqueryui.com/ticket/9518 - present中的一个错误。我也遇到了同样的问题并解决了它。由于我无法将页面的编码更改为UTF-8,因此我最终修补了我的jqueryui并使用了Rainer Plumer的解决方案作为变通方法,但我不得不使用它两次,因为我有一些包含编码的URI的URI参数。所以我的解决方案是
decodeURIComponent( unescape( unescape(s)) )
更一般的情况下,可能会有repeat-until循环,在得到相同的结果之前不会进行转义。这个变通方法肯定不是一个干净的解决方案。在这里询问干净的解决方案:
Submit form with get method in non UTF-8 encoding
PS: jquery UI的完整补丁:
function isLocal( anchor ) {
return anchor.hash.length > 1 &&
decodeURIComponent( unescape( unescape( anchor.href.replace( rhash, "" ) ) ) ) ===
decodeURIComponent( unescape( unescape( location.href.replace( rhash, "" ) ) ) );
}
发布于 2013-05-20 04:14:41
这是decodeURIComponent方法的结果,该方法假设给定字符串的百分比编码字节为UTF-8 (参见Decode operation的步骤4.d.vii.8,单位为秒)。ECMAScript的15.1.3 )。您的示例字符串:
"file:///C:/Work/my%20project/yadda%20ac%E7%F5es%20yadda/submenu.html#tabs-1"
包含百分比解码的字节0xE7 0xF5,它不能在有效的UTF-8字符串中一个接一个地出现(它们表示Windows1252中的两个字符çõ
)。因此,decodeURIComponent会抛出一个URIError异常。
解决这个问题的一种方法是确保您的网页使用UTF8字符编码,而不是我认为默认的ISO-8859-1
。
为此,请包含一个META标记,如下所示:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
(虽然理想的做法是包含一个包含字符集的Content-Type头,但在涉及文件系统的本地测试中,这通常是不可能的。)
并确保Web页面本身是以UTF-8编码的。
另外,您的示例字符串显示在Web页面的什么位置?它是如何生成的?您是在哪种浏览器上测试该行为的?答案将帮助我告诉你该怎么做。
发布于 2013-10-31 09:36:46
像这样的东西?
s = "file:///C:/Work/my%20project/yadda%20ac%E7%F5es%20yadda/submenu.html#tabs-1";
decodeURIComponent( unescape(s) )
https://stackoverflow.com/questions/15326777
复制相似问题