Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

javascript - replace text on keyup without showing default value

I'm developing a virtual Turkish alphabet keyboard. I'm trying to replace "ed" with "??", it works well however it shows "ed" before replacing. How can I get rid off that ? Note that if your computer doesn't have Unicode 6 or more it won't show you the special character which is a skinny X.

$('#text').keyup(function(e) {
  $('#text').css('direction', 'rtl');
  $('#text').css('unicode-bidi', 'bidi-override');
  text2 = $(this).val();
  text2 = text2.replace(/(ed)/g, "??");
  $("#text").val(text2);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="text"></textarea>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use input event instead.

$('#text').on('input', function(e) {
  $('#text').css('direction', 'rtl');
  $('#text').css('unicode-bidi', 'bidi-override');
  text2 = $(this).val();
  text2 = text2.replace(/(ed)/g, "??");
  $("#text").val(text2);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="text"></textarea>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...