【发布时间】:2015-06-22 04:28:05
【问题描述】:
“Return False”似乎只在内联工作,而不是在文档中。
这行得通:
<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返回,但不是从事件处理程序返回。
标签: javascript html javascript-events