i want to replace the content of the textarea with the list of my "replacements". so that "Hi 23" is going to be "\u041D\u0456 23". whats my mistake?
$("textarea#comment").val(function(i, val) {
return val.replace(/*the first letter (e.g. A)*/g, "*the second row e.g. \u0410*");
});
replacements = {
"A": "\u0410",
"B": "\u0412",
"C": "\u0421",
"H": "\u041D",
"I": "\u0406",
"J": "\u0408",
"M": "\u041C",
"O": "\u041E",
"P开发者_开发知识库": "\u0420",
"S": "\u0405",
"T": "\u0422",
"V": "\u0474",
"Y": "\u04AE",
"a": "\u0430",
"c": "\u0441",
"e": "\u0435",
"h": "\u04BB",
"i": "\u0456",
"j": "\u0458",
"l": "\u04C0",
"o": "\u043E",
"p": "\u0440",
"s": "\u0455",
"y": "\u0443",
"v": "\u0475";
}
var replacements = {
"A": "\\u0410",
"B": "\\u0412",
"C": "\\u0421",
"H": "\\u041D",
"I": "\\u0406",
"J": "\\u0408",
"M": "\\u041C",
"O": "\\u041E",
"P": "\\u0420",
"S": "\\u0405",
"T": "\\u0422",
"V": "\\u0474",
"Y": "\\u04AE",
"a": "\\u0430",
"c": "\\u0441",
"e": "\\u0435",
"h": "\\u04BB",
"i": "\\u0456",
"j": "\\u0458",
"l": "\\u04C0",
"o": "\\u043E",
"p": "\\u0440",
"s": "\\u0455",
"y": "\\u0443",
"v": "\\u0475"
}
$("textarea#comment").val(function(i, val)
{
val = val.split('');
$.each(val, function(i,e){
val[i] = replacements[e] ? replacements[e] : e;
});
return val.join('');
});
http://jsfiddle.net/6A2JG/
精彩评论