本文實例講述了JavaScript獲取網頁表單action屬性的方法。分享給大家供大家參考。具體如下:
JavaScript獲取網頁表單的action屬性,即要提交到的url地址,有時候需要提交到當前頁面,則可能會設置action為空
<!DOCTYPE html>
<html>
<body>
<form id="frm1" action="cnblogs.php">
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>
運行結果如下:
The value of the action attribute is:cnblogs.php
希望本文所述對大家的javascript程序設計有所幫助。