Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

1 of 6
Basic Block
  • 781
  • 10
  • 19

javascript and jquery array each

I cant get this to work. I am trying to replace certain characters when a key is pressed. It works fine when I use the variable replace_list instead of replace_list[0], but I need different "replace lists" for other things. What am I doing wrong?

replace_list[0] = {'a' : 'а', 'A' : 'А', 'b' : 'б', 'B' : 'Б', 'v' : 'в', 'V' : 'В', 'g' : 'г', 'G' : 'Г', 'd' : 'д', 'D' : 'Д', 'ye' : 'е', 'YE' : 'Е', 'yo' : 'ё', 'YO' : 'Ё', 'zh' : 'ж', 'ZH' : 'Ж', 'z' : 'з', 'Z' : 'З', 'i' : 'и', 'I' : 'И', 'j' : 'й', 'J' : 'Й', 'k' : 'к', 'K' : 'К', 'l' : 'л', 'L' : 'Л', 'm' : 'м', 'M' : 'М', 'n' : 'н', 'N' : 'Н', 'o' : 'о', 'O' : 'О', 'p' : 'п', 'P' : 'П', 'r' : 'р', 'R' : 'Р', 's' : 'с', 'S' : 'С', 't' : 'т', 'T' : 'Т', 'u' : 'у', 'U' : 'У', 'f' : 'ф', 'F' : 'Ф', 'kh' : 'х', 'KH' : 'Х', 'ts' : 'ц', 'TS' : 'Ц', 'ch' : 'ч', 'CH' : 'Ч', 'sh' : 'ш', 'SH' : 'Ш', 'shch' : 'щ', 'SHCH' : 'Щ', '"' : 'ъ', '"' : 'Ъ', 'y' : 'ы', 'Y' : 'Ы', ''' : 'ь', ''' : 'Ь', 'e' : 'э', 'E' : 'Э', 'yu' : 'ю', 'YU' : 'Ю', 'ya' : 'я', 'YA' : 'Я'}; $(document).ready(function() {

 $("#answer").keydown(function() {
 if($.cookie("trans") == "true"){
 var text = $(this).val();
 $.each(replace_list[0], function(index, value) { 
 if(index == text.substring(text.length - value.length)){
 $("#answer").val(text.substring(0, text.length - value.length) + value); 
 }
 });
 }
 });
})
Basic Block
  • 781
  • 10
  • 19
lang-js

AltStyle によって変換されたページ (->オリジナル) /