ASCII control character html input text

前端 未结 5 1223
盖世英雄少女心
盖世英雄少女心 2021-02-08 10:00

I\'m trying to process input from a barcode scanner in a javascript browser app. The scanner output is a string of characters, which also contains at least one Group Separator c

5条回答
  •  你的背包
    2021-02-08 10:41

    Firefox doesn't transmit ALT keypress, but only keydown and keyup events.
    This work for me in each browser:

    //GS1 Datamatrix  in Firefox, Chrome & IE
    var altValue = '';
    document.getElementById('SKAN').addEventListener('keydown', function(e) {
        if(e.altKey){
            if(e.which != 18){
               altValue += e.which
            }
            if(altValue === '969698105'){
               this.value += String.fromCharCode(29);
            }
        }
    });
    document.getElementById('SKAN').addEventListener('keyup', function(e) {
        if(e.altKey === false){
          altValue = '';
        }
    });
    

提交回复
热议问题