本文共 1034 字,大约阅读时间需要 3 分钟。
- function forbidBackSpace(e) {
- var ev = e || window.event;
- var obj = ev.target || ev.srcElement;
- var t = obj.type || obj.getAttribute('type');
-
- var vReadOnly = obj.readOnly;
- var vDisabled = obj.disabled;
-
- vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
- vDisabled = (vDisabled == undefined) ? true : vDisabled;
-
-
- var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
-
- var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
-
- if (flag2 || flag1) return false;
- }
- document.onkeypress = forbidBackSpace;
- document.onkeydown = forbidBackSpace; http://blog.csdn.net/maxuyang1987/article/details/9811843
转载于:https://www.cnblogs.com/Echo529/p/6382317.html