JavaScript获取网页表单的action属性,即要提交到的url地址,有时候需要提交到当前页面,则可能会设置action为空,下面代码提取到的action属性也为空。
<!DOCTYPE html>
<html>
<body>
<form id="frm1" action="sharejs.aspx">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>
<p>The value of the action attribute is:
<script>
document.write(document.getElementById("frm1").action);
</script>
</p>
</body>
</html>
输出结果:sharejs.aspx
