<script> <BR>var code = function () { <BR>return false; <BR>}; <BR>var element = window.document.getElementById("form"); <BR>if (element.addEventListener) { <BR>element.addEventListener("submit", code, false); <BR>} <BR></script>
修改后的Code:
<script> <BR>var code = function (eventObject) { <BR>if (eventObject.preventDefault) { <BR>eventObject.preventDefault(); <BR>} else if (window.event) /* for ie */ { <BR>window.event.returnValue = false; <BR>} <BR>return true; <BR>}; <BR>window.onload = function(){ <BR>var element = window.document.getElementById("form"); <BR>if (element.addEventListener) { <BR>element.addEventListener("submit", code, false); <BR>} else if (element.attachEvent) { <BR>element.attachEvent("onsubmit", code); <BR>} <BR>} <BR></script>
备注:
1:preventDefault函数的使用请参考 https://developer.mozilla.org/en/DOM/event.preventDefault
2:DOM Events :http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event-preventDefault