-1

我在书籍文件夹中有 html 文件。尝试在另一个 html 页面中使用 jQuery 加载方法加载 html 文件,但它显示外来字符,例如 �。

代码:

PageContentURL = "books/" + bookTitle + "/book_" + bookTitle;

$("#container").load(PageContentURL);

工作网址: http ://ashapanchal.com/TheBibleScholarHTML/chaptercontent.html?bid=2&btitle=Eastons%20Bible%20Dictionary&cid=4&ctitle=D&spi=186&epi=220&tpi=186

为什么会这样?如何去除外来字符?我已经设置了字符集并尝试了许多在线可用的解决方案。

4

3 回答 3

1

您需要在Apacheserver 上配置响应标头。

您现在拥有的只是文件'Content-Type: text/html'的标题.html。因此,您需要创建.htaccess文件(如果不存在)并添加以下行:

<FilesMatch "\.html$">
    Header unset Content-Type
    Header append Content-Type "text/html; charset=utf-8"
</FilesMatch>
于 2012-05-18T20:57:38.677 回答
0

你能试试这个代码吗:))

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);
        });
});​
于 2012-05-18T20:47:20.607 回答
0

从 chaptercontent.html 中删除以下行

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

问题是主页是使用 utf-8 编码的,而您包含的页面是 iso-8859-1。因为主页是 utf-8,所以它也将包含的页面解释为 utf-8。

于 2012-05-19T10:19:51.073 回答