允许对输入框密码框等控件删除字符,但是不允许页面进行回退

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script> window.onload = function (e) {
//禁止后退键 作用于Firefox、Opera
document.onkeypress = backspace;
//禁止后退键 作用于IE、Chrome
document.onkeydown = backspace;
} function backspace(e) {
var ev = e || window.event;//获取event对象
var obj = ev.target || ev.srcElement;//获取事件源
var t = obj.type || obj.getAttribute('type');//获取事件源类型
if (ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea") {
return false;
}
}
</script>
</head>
<body>
<h2>Page 2</h2>
<input type="text"/>
</body>
</html>
05-11 20:57