如何在JavaScript中将DOM节点文本值转换为UTF-8?
我需要通过Ajax请求发送HTML节点的文本内容,但首先将其转换为UTF-8。可能吗 谢谢如何在JavaScript中将DOM节点文本值转换为UTF-8?,javascript,character-encoding,Javascript,Character Encoding,我需要通过Ajax请求发送HTML节点的文本内容,但首先将其转换为UTF-8。可能吗 谢谢 function encode_utf8( s ) { return unescape( encodeURIComponent( s ) ); } function decode_utf8( s ) { return decodeURIComponent( escape( s ) ); } 从 像这样使用它 encode_utf8(document.getElementById(id).tex
function encode_utf8( s )
{
return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s )
{
return decodeURIComponent( escape( s ) );
}
从
像这样使用它
encode_utf8(document.getElementById(id).textContent);
从
像这样使用它
encode_utf8(document.getElementById(id).textContent);
@spektom如果使用GET方法发送内容,则
encodeURIComponent
就足够了,不需要这些破解。@spektom如果使用GET方法发送内容,则encodeURIComponent
就够了,不需要这些破解。