使用javascript,可以将onsubmit =“return selection()”添加到表单中吗?

时间:2016-09-06 11:32:32

标签: javascript

如何使用javascript向表单添加onsubmit =“return selection()”函数?

请参见此处:JSFIDDLE

id="product_configure_form"

1 个答案:

答案 0 :(得分:0)

  

使用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>
&#13;
&#13;
&#13;