如何在JavaScript中将DOM节点文本值转换为UTF-8? [英] How to convert DOM node text value to UTF-8 in JavaScript?
本文介绍了如何在JavaScript中将DOM节点文本值转换为UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过Ajax请求发送HTML节点的文本内容,但首先将其转换为UTF-8。是否可能?
I need to send a text content of an HTML node over Ajax request, but first convert it to UTF-8. Is that possible?
谢谢!
推荐答案
function encode_utf8( s )
{
return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s )
{
return decodeURIComponent( escape( s ) );
}
来自 http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
使用它...
encode_utf8(document.getElementById(id).textContent);
这篇关于如何在JavaScript中将DOM节点文本值转换为UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文