如何禁用在文本框中粘貼特殊字符?如何禁用在文本框中粘貼特殊字符
進出口使用關於onkeypress事件的事件處理程序
function disableOtherChar(evt) {
var charCode;
charCode = (evt.which) ? evt.which : evt.keyCode;
var ctrl;
ctrl = (document.all) ? event.ctrlKey : evt.modifiers & Event.CONTROL_MASK;
if ((charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 8 || charCode == 9 || charCode == 45 || (ctrl && charCode == 86) || ctrl && charCode == 67) {
return true;
} else {
$(":text").live("cut copy paste", function (e) {
e.preventDefault();
});
return false;
}
}
但它不阻止粘貼時,只有在輸入特殊字符,
嘗試處理'onpaste'事件以及 –
我試過,但它不起作用 – JeAr
什麼都行不通 - 你能詳細說明一下嗎?與一次處理一個字符的按鍵不同 - 使用onpaste,您將必須使用已經有無效字符的完整字符串,只需將其刪除即可 –