JS onsubmit onreset事件

<!-- onsubmit事件的事件源是form标签 -->
<form action="1.html" method="post">
    用户名:<input type="text" name="username"><br>
    密码:<input type="text" name="password"><br>
    <input type="submit">
    <input type="reset">
</form>

<script type="text/javascript">
    var form = document.getElementsByTagName('form')[0];

    form.onsubmit = function() {
        alert('我被提交了!!!!!');
        return false;
    }

    form.onreset = function() {
        alert('我被重置了!!!');
        return false;
    }
</script>