0
“返回False”似乎只工作在内联,而不是在文档中。Javascript返回False在html中的作用,而不是头
这工作:
<html><body><form action="index.html" method="post">
<input type="submit" onClick="alert('Hello'); return false;">
</form>
</body></html>
这不起作用:
<html><head>
function myfunction(){
alert("Hello");
return false;
}
</head>
<body>
<form action="index.html" method="post">
<input type="submit" onClick="myfunction();">
</form>
</body></html>
您还没有发布什么作品? –
这是为什么令人惊讶?在第一种情况下,您将从事件处理程序返回某些内容,在第二种情况下,您不会。你从'myfunction'返回,而不是从事件处理程序返回。 –