Formar caso onsubmit
Definición y Uso
evento onsubmit llama cuando se envía el formulario.
gramática
onsubmit="JavaScriptCode"
参数 | 描述 |
---|---|
JavaScriptCode | 必须。事件触发后指定执行的 JavaScript 代码。 |
Soporte para el navegador
Todos los principales navegadores soportan caso onsubmit
Ejemplos
Ejemplos
Cuando el botón de enviar, haga clic para enviar el formulario para mostrar un marco de ventana emergente:
<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>
Trate »
objeto de formulario