使用javascript,可以将onsubmit =“return selection()”添加到表单中吗?
问题描述:
如何添加一个onsubmit =“return selection()”函数到使用javascript的窗体?使用javascript,可以将onsubmit =“return selection()”添加到表单中吗?
请看这里:JSFIDDLE
id="product_configure_form"
答
围棋与
JavaScript-Event-Binding
和使用event.preventDefault()
,而不是接近onsubmit="return selection()"
$('#product_configure_form').on('submit', function(e) {
e.preventDefault();
alert('Form submission is prevented..');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="add-to-cart clearfix" action="http://www.photographycoursetour.com/cart/add/46111438/" id="product_configure_form" method="post">
<input type="text">
<input type="submit">
</form>
围棋'JavaScript-Event-Binding'并使用'event.preventDefault()'而不是接近'onsubmit =“return selection()”' – Rayon
你是什么意思“将它添加到使用javascript的窗体”?你不能只是将该代码输入到'form'元素中?你试图完成什么? – David
谢谢!那将如何看待人造丝?如果我可能会问,你能否更新JSFIDDLE? – Eddy