jquery提交表单->只发布可见数据
我有一个带有很多单选按钮的表单。根据您的选择,将显示不同的按钮组。有没有办法只在用户按下提交按钮时发布可见按钮?谢谢
I have a form with a lot of radiobuttons. Depending on what you choose, different sets of buttons will be shown. Is there any way to only post the visible buttons when a user presses a submit button? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以挂钩提交功能:
然后执行 AJAX post,其中数据为 $('input:visible'),或删除隐藏元素等。
注意:返回 false 会阻止提交!
You can hook the submit function:
Then do an AJAX post where the data is $('input:visible'), or remove the hidden elements, etc.
Note: returning false prevents the submission!
仅当您手动触发表单提交时,您才能过滤单选按钮,例如使用
.click(fn)
或.submit(fn)
函数。例如
You can filter radio buttons only if you trigger form submit manually for example with
.click(fn)
or.submit(fn)
function.For example
可能,但您应该依靠服务器端逻辑来确保没有人向您发送“捏造”的数据。
您可以通过在提交之前从表单中删除隐藏的控件来实现这一点,如下所示(jQuery):-
这将删除所有隐藏的输入控件。不过,我真的不会特别推荐这样做(如果您在 .net 中执行此操作,请务必小心,因为这会终止视图状态和事件验证。
probably, but you should be relying on server side logic to ensure nobody is sending you 'fudged' data anyway.
You could probably do it by removing the hidden ones from the form prior to the submission like this (jQuery):-
This will remove all hidden input controls. I really wouldn't particularly recommend this however (and be very careful if you are doing this in .net as this will kill viewstate and event validation.