HTML教程-HTML 表单操作
action 是 <form>
元素的一个属性,用于指定第二个网页的 URL。第二个页面在表单提交后接收来自第一个页面的表单数据。
语法
<form action="页面的URL">..............</form>
这个属性的值是一个网页的URL,用于接收用户填写的表单信息。
示例
<!DOCTYPE html>
<html>
<head>
<title>Example of HTML form action</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
font-family: Calibri, Helvetica, sans-serif;
background-color: pink;
}
.container {
padding: 50px;
background-color: lightblue;
}
input[type=text] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
input[type=text]:focus {
background-color: orange;
outline: none;
}
div {
padding: 10px 0;
}
.registerbtn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<center><h1>Student Registration Form</h1></center>
<form action="jp.html" method="post">
<label> Firstname </label>
<input type="text" name="firstname" placeholder="Firstname" size="15" required />
<label> Lastname: </label>
<input type="text" name="lastname" placeholder="Lastname" size="15" required />
<div>
<label>
Gender :
</label><br>
<input type="radio" value="Male" name="gender" checked /> Male
<input type="radio" value="Female" name="gender" /> Female
<input type="radio" value="Other" name="gender" /> Other
<div>
<label>
Phone :
</label>
<input type="text" name="phone" placeholder="phone no." size="10" required />
</div>
<button type="submit" class="registerbtn">Register</button>
</form>
After clicking on the submit button, the values of the form are sent to the jp.php page with the help of a server. If you want to learn the process of a server, then click on this URL: [https://www.javatpoint.com/php-form](https://www.javatpoint.com/php-form)
</div>
</body>
</html>
这个示例在点击 register 按钮后,通过服务器的帮助将填写的值发送到 jp.php 页面。
浏览器支持
元素 | Chrome | IE | Firefox | Opera | Safari |
---|---|---|---|---|---|
<form action=" "> | 是 | 是 | 是 | 是 | 是 |