onsubmit事件创建的两种方式

<form onsubmit="return check();">
    <input type="text" name="username">
    <input type="submit" value="提交">
</form>
<script>
    function check() {
        alert("验证失败");
        return false;

    }
</script>

//第二种
<form id="form_submit">
    <input type="text" name="username">
    <input type="submit" value="提交">
</form>
</body>
<script>
    var form_subm = document.getElementById("form_submit");
    form_subm.onsubmit = function (event) {
        alert("验证失败");
        return false;
    }

猜你喜欢

转载自www.cnblogs.com/TKOPython/p/12823997.html