有時候在使用表單的時候,不一定會用到表單中的input_submit來提交表單數據,可能會用a、button等來代替,我們可以JS中的提交表單數據的動作
代碼如下:
設置form頭部如下:添加id是為了在java script腳本中進行中獲取form對象
<!--格式一-->
<form id="mainForm" action="{% url 'index' %}" method="post">
<a href="javascript:void(0)" onclick="document.getElementById('mainForm').submit();return false;">提交</a>
</form>
<!--格式一-->
<form id="mainForm" action="{% url 'index' %}" method="post">
<a href="javascript:void(0)" onclick="document:mainForm.submit();return false;">提交</a>
</form>
這樣就可以用a標簽提交form表單中的數據了。
為您推薦: