フォームタグ内に次のものを含めることはできますか?
action="handler"
これは合法ですか?おそらく何らかのJavaScript関数を実行します。
フォームタグ内に次のものを含めることはできますか?
action="handler"
これは合法ですか?おそらく何らかのJavaScript関数を実行します。
属性は、action
ブラウザがフォームを送信する URL です。
<form action="submitForm.php"><input /></form>
JavaScript を実行したい場合は、handler
次のように作成できます。
<form action="javascript:myFunc(this)"><input /></form>
これを行わず、代わりに JavaScript イベント ハンドラーを使用してイベントをキャプチャすることを強くお勧めしますonsubmit
。
<form id="myForm"><input /></form>
<script>
document.getElementById('myForm').addEventListener('submit', function(event){
event.preventDefault(); // prevent the form the submitting.
// the form will only submit if
// it has an "action" attribute
myFunc(this);
});
</script>
はい、合法ですが、javascript を呼び出しません。「handler」で指定されたサーバー URL にフォームを送信します。