I want to ignore certain characters in my phone input, so that the database just has digits. I know I can do this easy on server side (using PHP) but I am trying to understand js events a little better.. My question is this:
If I have a basic input:
var phoneInput = document.getElementById("phoneInput");
I can add an event listener using "onkeydown" which works fine
phoneInput.onkeydown = function(e){
var c = String.fromCharCode(e.keyCode);
var patt = /d/;
if(!patt.test(c)) return false;
};
But if I try doing the same thing using 'addEventListener', returning false seems to do nothing
phoneInput.addEventListener("keydown",function(e){
var c = String.fromCharCode(e.keyCode);
var patt = /d/;
if(!patt.test(c)) return false;
});
I just don't understand why. Thanks in advance for any light you can shine on the subject..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…