HTML DOM 输入提交 formTarget 属性
HTML DOM 输入提交 formTarget 属性用于设置或返回提交按钮的 formTarget 属性值。HTML DOM 输入提交 formTarget 属性是服务器响应应在表单数据提交后显示的位置。formTarget 属性覆盖表单元素的 target 属性。它在 HTML5 中引入,输入元素类型为提交。
语法
以下是语法 −
设置 formTarget 属性 −
submitObject.formTarget = "_blank|_self|_parent|_top|framename"
在此,_blank 将在新窗口中打开响应;_self 将在同一窗口中打开响应;parent 将在父框架中打开;_top 将在整个窗口正文中打开;而 framename 将在指定名称的框架中打开。
范例
我们来看一个提交 formTarget 属性的例子 −
<!DOCTYPE html>
<html>
<body>
<h1>Submit formTarget property</h1>
<form id="FORM_1" action="/Sample.php" style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Loc"> <br><br>
<input type="submit" id="SUBMIT1" formtarget=_self>
</form>
<p>View the form response in the new window instead of same window by clicking the below button</p>
<button onclick="changeTarget()">CHANGE</button>
<p id="Sample"></p>
<script>
function changeTarget() {
document.getElementById("SUBMIT1").formTarget="_blank";
document.getElementById("Sample").innerHTML = "The response will now open in the new window";
}
</script>
</body>
</html>结果
这将产生以下结果 −

点击更改按钮 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP