我可以制作一组不随表单提交的单选按钮吗?
我有一组单选按钮,位于属于 HTML 表单一部分的其他控件之间。我不希望这些单选按钮的值与查询一起提交(我只是将这些单选按钮用于 JavaScript 内容)。通常,我可以通过不为其他控件(即复选框等)设置“名称”属性来执行此操作,并且它们不会被提交。但是,为了使单选按钮具有“互斥”行为,需要“名称”属性。我也无法将单选按钮移到表单之外,因为它位于需要与表单一起提交的其他控件之间。另外,我无法禁用单选按钮,因为我需要用户能够单击它们。那么有没有一种方法可以制作一组不与表单一起提交的单选按钮?
I have a set of radio buttons that is in between other controls that are part of an HTML form. I do not want the value of these radio buttons to be submitted with the query (I am just using these radio buttons for JavaScript stuff). Normally, I can do this with other controls (i.e. checkboxes, etc.) by not having a "name" attribute for them, and they won't get submitted. However, the "name" attribute is required in order for radio buttons to have their "mutually-exclusive" behavior. I cannot move the radio buttons outside of the form either, because it's situated in between other controls that do need to be submitted with the form. Also, I cannot disable the radio buttons because I need the user to be able to click them. So is there a way I can make a set of radio buttons that do not get submitted with the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以想到几个解决方案:
中的元素
一种是将按钮放置在表单内的 iframe 内,然后仅关闭 iframe 的边框,以便给人留下他们在形式上的印象。
在“提交”期间删除
另一个解决方案是通过表单提交操作上的 JavaScript 从表单中删除元素,将截断的元素列表发送回服务器。
如果是我,我会忽略服务器端的元素。
I can think of a couple solutions:
Elements in an
<iframe />
One would be to place the buttons within an iframe, within your form, and merely turn the border of the iframe off so as to give the impression they are in the form.
Remove during "Submit"
Another solution would be to remove the element from the form via Javascript on the forms submit action, sending a truncated list of elements back to the server.
If it were me, I'd just ignore the elements on the server-side.
在这个问题上你有几个选择。
形式。例如,您可以
将单选按钮“放置”在
视觉形式区域,实际上没有
通过使用将代码包含在表单中
CSS 的。
说。
元素,例如 JqueryUI
按钮组
http://www.filamentgroup.com/lab/styling_buttons_and_toolbars_with_the_jquery_ui_css_framework/
注意,没有名字未测试
元素,但可以想象应该可以工作。
You have a few options on this one.
the form. For example, you could
"place" the radio buttons in the
visual form area without actually
having the code in the form via use
of CSS.
said.
element such as the JqueryUI
buttonset
http://www.filamentgroup.com/lab/styling_buttons_and_toolbars_with_the_jquery_ui_css_framework/
Note, not tested without name
element, but conceivably should work.
如果您不关心有效性,您仍然可以使用单选按钮,而不给它们命名。你的 JS 可以通过它们的 ID 来识别它们,如果没有名字,它们就不会传递任何参数。
If you didn't care about validity, you could still have the radio buttons, and not give them names. Your JS can identify them by their IDs, and without names, they won't pass any parameters.