如何在 HTML 中使用 formtarget 屬性?


HTML 中的 formtarget 屬性用於指明在提交表單後收到的響應顯示在哪。它將覆蓋 HTML 表單標記的 target 屬性。formtarget 屬性僅與提交表單的 input type 和圖片一起使用。

以下是 formtarget 屬性的屬性值:

序號
說明
1
_blank
響應將在新視窗或標籤頁中顯示
2
_self
預設值。響應將在相同的框架中顯示。
3
_parent
響應將在父框架中顯示
4
_top
響應將顯示在視窗的正文中
5
framename
響應將顯示在命名的 iframe 中


示例

你可以嘗試執行以下程式碼來了解如何在 HTML 中使用 formtarget 屬性。

<!DOCTYPE html>
<html>
   <head>
      <title>HTML formtarget attribute</title>
   </head>
   <body>
      <form action = ”/new.php” method = "get">
         Student Name<br><input type = "text" name = "name"/><br>
         Student Subject<br><input type = "text" name = "subject"/><br>
         <input type = "submit" value = "Submit">
         <input type = "submit" formtarget = "_blank" value="Submit (new window)">
      </form>
   </body>
</html>

更新於: 2020 年 6 月 15 日

204 次瀏覽

開啟您的職業生涯

完成課程獲得認證

開始學習
廣告