0

フォームタグ内に次のものを含めることはできますか?

action="handler"

これは合法ですか?おそらく何らかのJavaScript関数を実行します。

4

2 に答える 2

2

属性は、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>
于 2012-05-30T20:32:51.743 に答える
2

はい、合法ですが、javascript を呼び出しません。「handler」で指定されたサーバー URL にフォームを送信します。

于 2012-05-30T20:27:18.160 に答える