Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

แอตทริบิวต์ action ของฟอร์ม HTML

แอตทริบิวต์ action ของฟอร์ม HTML ใช้กำหนดที่จะส่งข้อมูลฟอร์มไปที่ไหนเมื่อฟอร์มถูกส่งในเอกสาร HTML

ไวยากรณ์

ไวยากรณ์มีดังนี้ −

<form action="URL"></form>

ลองดูตัวอย่างการใช้งานแอตทริบิวต์ action ของฟอร์ม HTML −

ตัวอย่าง

<!DOCTYPE html> <html> <style>    body {       color: #000;       height: 100vh;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;       text-align: center;    }    input {       width: 315px;       display: block;       margin: 1rem auto;       border: 2px solid #fff;       padding: 8px;       background: transparent;       border-radius: 20px;       outline: none;    }    ::placeholder {       color: #000;    }    .btn {       background: #db133a;       border: none;       height: 2rem;       border-radius: 20px;       width: 330px;       display: block;       color: #fff;       outline: none;       cursor: pointer;       margin: 1rem auto;    } </style> <body> <h1>การสาธิตแอตทริบิวต์ action ของฟอร์ม HTML</h1> <form action="/action_page.php" method="get"> <input type="text" name="firstname" placeholder="ป้อนชื่อ"> <input type="text" name="lastname" placeholder="ป้อนนามสกุล"> <input type="submit" value="ส่ง" class="btn"> </form> </body> </html>

ผลลัพธ์

กรอกรายละเอียดฟอร์ม แล้วส่งฟอร์มโดยใช้ปุ่ม ส่ง เพื่อสังเกตการทำงานของแอตทริบิวต์ action −

แอตทริบิวต์ action ของฟอร์ม HTML

แอตทริบิวต์ action ของฟอร์ม HTML