具有不同名称的单选按钮?

发布于 2024-08-31 11:38:34 字数 231 浏览 1 评论 0原文

有没有人有无JavaScript的方法来使属于同一“组”的HTML单选按钮具有不同的“名称”属性?

虽然我认为没有任何办法,但我正在开发一个在 JS 关闭时仍需要运行的网站,这将是理想的选择。

附录 这与其说

是要求,不如说是偏好;我试图尊重发布的参数的格式和命名的解决方案的一致性。当然,如果需要的话,我会放弃它,但如果我能让它发挥作用,我会得到那种温暖模糊的感觉......

Does anyone have a no JavaScript way to make HTML radio buttons belonging to the same "group" have different "name" attributes?

While I figure there isn't any way, I'm working on a site which needs to still be function when JS is off, and this would be ideal.

Addendum

It's not a requirement as much as a preference; there's a kind of consistency in the solution I'm trying to respect about the format and naming of parameters which get POSTed. Of course, if need be, I'll ditch it, but if I can make it work I'll get that warm fuzzy feeling...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

有深☉意 2024-09-07 11:38:34

根据 HTML 4.01 规范,名称定义 组,所以不,我认为不会有非 JavaScript 的方法来做到这一点。

您想要实现什么目标,以便需要将具有不同名称属性的单选按钮视为同一组的一部分?您可以使用 id 或 class 属性来区分它们以实现您想要做的任何事情吗?

According to the HTML 4.01 spec, the name defines the group, so no, I don't think there'll be a non-JavaScript way to do this.

What are you trying to achieve such that you need radio buttons with different name attributes to be considered as part of the same group? Can you use the id or class attributes to differentiate them for whatever you're trying to do?

卖梦商人 2024-09-07 11:38:34

刚刚遇到这个问题,然后为我的功能解决了它,我知道这是一个旧线程,但正如我在 20 分钟前发现此信息有用一样,这就是我所做的:

将它们用相同的名称属性分组,但在它们之后区分它们通过检查 post 数组中的值来提交。即

`

// first radio button
if ($_POST['someValue'] == 'someString') {

  // do something

// second radio button
} elseif ($_POST['someValue'] == 'anotherString') {

  // do something else

}

`

希望这对将来的人有用

Just came across this then solved it for my functionality, I know it's an old thread but as I would have found this info useful 20 minutes ago here's what I did:

keep them grouped with the same name attribute, but differentiate between them after they have been submitted by checking their value in post array. i.e.

`

// first radio button
if ($_POST['someValue'] == 'someString') {

  // do something

// second radio button
} elseif ($_POST['someValue'] == 'anotherString') {

  // do something else

}

`

hope that's useful to someone in the future

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