【发布时间】:2017-09-27 21:50:39
【问题描述】:
我已经在我的网站上设置了一个简单的 AJAX 页面加载脚本,到目前为止一切正常,除了 <title> 中的 Unicode 字符在加载新内容时搞砸了。
我的 jQuery 设置如下所示:
jQuery(document).ready(function ($) {
"use strict";
var main = $("main");
menuLinks.click(function () {
var href = $(this).attr("href"),
ajaxLoad = function (html) {
document.title = html.match(/<title>(.*?)<\/title>/)[1].trim();
main.fadeIn('slow');
};
history.pushState(null, null, href);
main.fadeOut('slow', function () {
main.load(href + ' main>*', ajaxLoad);
});
return false;
});
});
我的<title> 中有破折号,加载页面标题时它们最终为&#8211;。我的印象是,这与使用不同编码的 jQuery 和 HTML 有关,但不知道如何解决问题。
【问题讨论】:
标签: javascript jquery ajax unicode