admin管理员组文章数量:1277899
I want to know if there are any jquery ponents which automatically take care of special characters.
This basically means converting &
to &
and also all listed in here, so that when I send data to the backend it stores in that format.
And then while retrieving we need to convert it back from &
to &
.
We will be using a lot of mathematical symbols so we need a functionality in JavaScript which does that. Also I have seen a rich text editor but we don't need lot of its features such as images, paragraph etc, though we want the text editor to have some icon or something to insert mathematics symbols and source code. In a nutshell, I'm looking something like the Stackoverflow editor, without images.
I want to know if there are any jquery ponents which automatically take care of special characters.
This basically means converting &
to &
and also all listed in here, so that when I send data to the backend it stores in that format.
And then while retrieving we need to convert it back from &
to &
.
We will be using a lot of mathematical symbols so we need a functionality in JavaScript which does that. Also I have seen a rich text editor but we don't need lot of its features such as images, paragraph etc, though we want the text editor to have some icon or something to insert mathematics symbols and source code. In a nutshell, I'm looking something like the Stackoverflow editor, without images.
Share Improve this question edited Sep 13, 2012 at 15:25 Nathan Koop 25.2k26 gold badges94 silver badges127 bronze badges asked Sep 13, 2012 at 15:05 user1595858user1595858 3,89017 gold badges72 silver badges111 bronze badges3 Answers
Reset to default 6You can use jQuery to do this for you:
function htmlEncode(value){
if (value) {
return jQuery('<div />').text(value).html();
} else {
return '';
}
}
function htmlDecode(value) {
if (value) {
return $('<div />').html(value).text();
} else {
return '';
}
}
$(document).ready(function() {
alert( htmlEncode ("this is a & test") );
});
Code originally from http://www.naveen..au/javascript/jquery/encode-or-decode-html-entities-with-jquery/289.
You didn't say how you were submitting things, but chances are encodeURIComponent
will be your friend.
https://developer.mozilla/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
The link was down when I posted, but Mozilla should be up and running soon.
The function encodeURIComponent($('#textarea').val())
will solve your problem.
本文标签: javascriptHow to escape special characters from textarea using jQueryStack Overflow
版权声明:本文标题:javascript - How to escape special characters from textarea using jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741234775a2362791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论