按钮元素上的onSubmit事件将起作用吗? [英] onSubmit event on a button element will it work?

查看:100
本文介绍了按钮元素上的onSubmit事件将起作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是代码。

<html>
    <head>
        <script type="text/javascript">
            function call() {
                alert("hai");
            }
        </script>
    </head>
    <body>
        <form name="login" method="post" action="">
            <input type="submit" name="Submit" value="login" onSubmit="call()">
        </form>
    </body>
</html>

是否可以创建事件 onSubmit 在输入元素中,键入 button

Is it possible to create an event onSubmit inside the input element type button.

这是一个赋值。我的老师告诉我这是可能的。

This is for an assignment. I was told by my tutor that it is possible. Any help would be highly appreciated.

谢谢。

推荐答案

您的 onsubmit 应该应用于表单,因为它是提交的表单,而不是按钮。

Your onsubmit should be applied to the form as it's the form that gets submitted - not the button.

HTML4规范


提交表单时发生onsubmit事件。 它仅适用于FORM元素。

这篇关于按钮元素上的onSubmit事件将起作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆