我可以制作一组不随表单提交的单选按钮吗?

发布于 2024-09-15 12:13:49 字数 255 浏览 4 评论 0原文

我有一组单选按钮,位于属于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

养猫人 2024-09-22 12:13:50

我可以想到几个解决方案:

中的元素

一种是将按钮放置在表单内的 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.

流年已逝 2024-09-22 12:13:50

在这个问题上你有几个选择。

You have a few options on this one.

小姐丶请自重 2024-09-22 12:13:50

如果您不关心有效性,您仍然可以使用单选按钮,而不给它们命名。你的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文