Form onsubmit 事件
定義和用法
onsubmit 事件在提交表單時調用。
語法
onsubmit="JavaScriptCode"
参数 | 描述 |
---|---|
JavaScriptCode | 必须。事件触发后指定执行的 JavaScript 代码。 |
瀏覽器支持
所有主要瀏覽器都支持onsubmit 事件
實例
實例
當submit按鈕點擊提交表單後顯示一個彈窗框:
<html>
<head>
<script>
function greeting()
{
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br>
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
<head>
<script>
function greeting()
{
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br>
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
嘗試一下»
Form對象