javascript - capture input and convert characters

后端 未结 3 1015
谎友^
谎友^ 2021-01-06 13:07

I want to capture input charcters in text box, convert then according to a table and put them back in text box as user types.

Ent
3条回答
  •  离开以前
    2021-01-06 13:13

    Should do the trick. Now works wherever caret is and even when you copy/paste WECZ into field (if that matters)

    var conversionMap = {W:1,E:2,R:3,S:4,D:5,F:6,Z:7,X:8,C:9};
    function alphaToNum(){
        var field = document.getElementById('idMyText');
        var value = field.value.split('');
        var i = 0, len = value.length;
    
        for(i;i

    its working good until we didn't use utf-8 chars like öéáí etc... any idea for repair this "leak" ?

提交回复
热议问题