简体   繁体   English

嵌套表单提交父表单

[英]Nested form submitting parent form

Having a problem with implementing an address finder at the moment.目前在实现地址查找器时遇到问题。 I have it all working on it's own, I give postcodeanywhere the postcode via json, it chucks back the addresses which I put in a select and then I give it back the chosen addresses id.我有它自己的所有工作,我通过 json 给 postcodeanywhere 邮政编码,它把我放在选择中的地址退回,然后我把它返回给选择的地址 id。

The problem comes when I integrate it into my shops checkout page.当我将它集成到我的商店结帐页面时,问题就出现了。 I do the address lookups via post and get in a form.我通过邮寄进行地址查找并获得表格。 When I hit the submit button for the address lookup it submits then whole shopping form as if I was going to buy something.当我点击地址查找的提交按钮时,它会提交整个购物表格,就好像我要买东西一样。

What I'm wondering is, if there's a better way to do it, ie not with forms or how to have a form within a form and only trigger the nested forms actions.我想知道的是,是否有更好的方法来做到这一点,即不使用表单或如何在表单中包含表单并且仅触发嵌套表单操作。 I assume I could use ajax but haven't been able to get anything working and assume this would still use the form element anyway?我假设我可以使用 ajax 但一直无法得到任何工作,并假设这仍然会使用表单元素?

You can stop the default form sublit 您可以停止默认窗体细分

$('#form').submit(function (evt) {
    evt.preventDefault();
    //do your postal code job
    $('#form').submit();
});

Though you can have several <form> elements in one HTML page, you cannot nest them. 尽管在一个HTML页面中可以有多个<form>元素,但是您不能嵌套它们。

You should use ajax/jquery ajax for address lookups 您应该使用ajax / jquery ajax进行地址查找

http://www.w3.org/MarkUp/html3/forms.html http://www.w3.org/MarkUp/html3/forms.html

您可以在嵌套表单提交处理程序上使用event.stopPropagation()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM