<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