英文:
Javascript gets wrong charset when using .text with Japanese characters
问题
I have a javascript function that toggles the text of a button when clicked:
$(function() {
$(".trigger-block").hide();
$(".trigger").click(function() {
$(this).parents(".more-cases").find(".trigger-block").slideToggle();
$(this).toggleClass("close");
$(this).text($(this).text() == "その他の事例を見る" ? "その他の事例を閉じる" : "その他の事例を見る");
});
});
It works with English but it outputs squares with question marks if I use Japanese.
I have charset=UTF-8
inside </head>
and also put it on the script tag with no success:
<script src="js/page.js" charset="UTF-8"></script>
Can someone guide me to the solution? I've searched on various Japanese forums and haven't found an answer. I've had success using Japanese with .append
so I don't know what is causing this problem.
EDIT: .append
works on a different js file but not this one. I'm still trying to figure out what is different between those files.
英文:
I have a javascript function that toggles the text of a button when clicked:
$(function() {
$(".trigger-block").hide();
$(".trigger").click(function() {
$(this).parents(".more-cases").find(".trigger-block").slideToggle();
$(this).toggleClass("close");
$(this).text($(this).text() == "その他の事例を見る" ? "その他の事例を閉じる" : "その他の事例を見る");
});
});
It works with English but it outputs squares with questions marks if I use Japanese.
I have charset=UTF-8 inside </head> and also put it on the script tag with no success.
<script src="js/page.js" charset="UTF-8"></script>
Can some guide me to the solution? I've searched on various Japanese forums and haven't found an answer. I've had success using Japanese with .append so I don't know what is causing this problem.
EDIT: .append works on a different js file but not this one. I'm still trying to figure out what is different between those files.
答案1
得分: 1
原来我正在编辑的原始文件没有正确编码。我通过简单地创建一个新的.js文件,并将原始代码复制到其中来解决了这个问题。感谢大家的支持!
英文:
Turns out the original file I was editing was not encoded properly. I've reached a solution by simply making a new .js file, and copying the original code to it. Thank you all for the support!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论