js禁用只读文本框获得焦点时的回格键
时间:2010-10-19 来源:qqhepp
<script>
document.documentElement.onkeydown = function(evt){
var b = !!evt, oEvent = evt || window.event;
if (oEvent.keyCode == 8) {
var node = b ? oEvent.target : oEvent.srcElement;
var reg = /^(input|textarea)$/i, regType = /^(text|textarea)$/i;
if (!reg.test(node.nodeName) || !regType.test(node.type) || node.readOnly || node.disabled) {
if (b)
{
oEvent.stopPropagation();
}
else
{
oEvent.cancelBubble = true;
oEvent.keyCode = 0;
oEvent.returnValue = false;
}
}
}
}
</script>
脚本来源:http://www.cnblogs.com/troubleLife/archive/2010/04/21/1716904.html