带有丹麦字符串的JavaScript UTF-8编码问题
我有一根长绳子,我想变成一个可下载的罚款。它有丹麦文字,可以翻译为� 或者视我是否尝试改变编码而定 这是我的代码:带有丹麦字符串的JavaScript UTF-8编码问题,javascript,encoding,utf-8,Javascript,Encoding,Utf 8,我有一根长绳子,我想变成一个可下载的罚款。它有丹麦文字,可以翻译为� 或者视我是否尝试改变编码而定 这是我的代码: function download(filename, text) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf8,'+text); element.setAttribute('download', fi
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf8,'+text);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
//element.click();
document.body.removeChild(element);
}
function encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
我试着对文本进行编码和解码,我试着输入字符集:utf8,utf-8,iso-8859-1。同样的结果。建议?您可以使用String.fromCharCode()而不是字符。例如,230相当于æÆ相当于Æ,等等
element.setAttribute('href', `http://www.Tr${String.fromCharCode(230)}kogslip.dk`);
我的用例涉及到设置涉及精细上传的文本
document.querySelector(".qq-uploader-selector").setAttribute("qq-drop-area-text", `Tr${String.fromCharCode(230)}k og slip filer her`);
您可以使用此网站作为查找HTML字符代码的参考。只要您始终正确设置内容类型,就不需要使用这些
编码和解码功能。你给他们打电话了吗?