编译没出现错误,但点击Error List 窗口显示很多错误,例如: Error:Another object on this page already uses ID 'mainframe'. Error:Validation (XHTML 1.0 Transitional): The values permitted for this attribute do not include 'absmiddle'. Error:Validation (XHTML 1.0 Transitional): This name contains uppercase characters, which is not allowed.
function backspace()
{
if (event.keyCode == 8 && event.srcElement.tagName != "INPUT" && event.srcElement.type != "text")
event.returnValue=false;
}
这样行么
<head>
<script>
function document.onkeypress(){
if (event.keyCode == 8)
{
event.returnValue=false;
event.cancel = true;
window.location.href='当前页面.aspx';
//window.location.reload();
}
}
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<script>
function keydown(){
if (event.keyCode == 8)
{
event.returnValue=false;
event.cancel = true;
window.location.href='a.html';
//window.location.reload();
}
}
</script>
</head>
<body onkeydown="keydown();">
</body>
</html>
不要写成这样了,这样捕获不到退格,只能捕获字母回车之类的消息。
用3楼的写法。
<html>
<head>
//head里写的
<script>
function keydown(){
if (event.keyCode == 8)
{
event.returnValue=false;
event.cancel = true;
window.location.href='a.html';//修改为你要跳转的url
//window.location.reload();
}
}
</script>
</head>
<body onkeydown="keydown();">//加了吗?
</body>
</html>这个我测试通过的,LZ再仔细好好看看。
......
如何body里有一个函数调用例如:
<body id="bottomBody" onload="MM_preloadImages('images/tabImg1Off.gif','images/tabImg2On.gif')" onkeydown="keydown();">
这样可以吗,按所用键都没进入,在onkeydown函数里我加了一句window.alert("ok");没有弹出
我给你的那段代码是正确的,我这里测试通过,你仔细检查一下,应该是你的页面里有问题。
或者把onkeydown换成onkeypress,onkeyup试试。
Error:Another object on this page already uses ID 'mainframe'.
Error:Validation (XHTML 1.0 Transitional): The values permitted for this attribute do not include 'absmiddle'.
Error:Validation (XHTML 1.0 Transitional): This name contains uppercase characters, which is not allowed.