我在书籍文件夹中有 html 文件。尝试在另一个 html 页面中使用 jQuery 加载方法加载 html 文件,但它显示外来字符,例如 �。
代码:
PageContentURL = "books/" + bookTitle + "/book_" + bookTitle;
$("#container").load(PageContentURL);
为什么会这样?如何去除外来字符?我已经设置了字符集并尝试了许多在线可用的解决方案。
我在书籍文件夹中有 html 文件。尝试在另一个 html 页面中使用 jQuery 加载方法加载 html 文件,但它显示外来字符,例如 �。
代码:
PageContentURL = "books/" + bookTitle + "/book_" + bookTitle;
$("#container").load(PageContentURL);
为什么会这样?如何去除外来字符?我已经设置了字符集并尝试了许多在线可用的解决方案。
您需要在Apache
server 上配置响应标头。
您现在拥有的只是文件'Content-Type: text/html'
的标题.html
。因此,您需要创建.htaccess
文件(如果不存在)并添加以下行:
<FilesMatch "\.html$">
Header unset Content-Type
Header append Content-Type "text/html; charset=utf-8"
</FilesMatch>
你能试试这个代码吗:))
str.replace(/[^\w\s]/gi, '');
如果你想试试
<input type='button' value='click' id="click"/>
<input type='text' value='' id="testtt"/>
$(function(){
$('#click').click(function(){
var str= $('#testtt').val();
var newvalue = str.replace(/[^\w\s]/gi, '');
alert(newvalue);
});
});
从 chaptercontent.html 中删除以下行
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
问题是主页是使用 utf-8 编码的,而您包含的页面是 iso-8859-1。因为主页是 utf-8,所以它也将包含的页面解释为 utf-8。