HTML:连接到选择列表的单选按钮

发布于 2024-08-12 10:26:12 字数 294 浏览 4 评论 0原文

请原谅我缺乏 html 知识,但是是否可以设置一组 3 个单选按钮,以便每个按钮链接到不同的选择项目列表?

我想做的是让用户选择:

项目选择所有项目的列表,
任务选择所有任务的列表,
用户选择所有用户的列表

据我所知,到目前为止,它们仅显示文本并具有提交值作为输入。难道我想的不可行吗?

我希望有一些简单的方法将单选按钮链接到每个选择列表,但在最坏的情况下我可以想象只有适当的选择列表通过 JavaScript 方法将其值放入单选按钮的值字段中。对于一个看似简单的想法来说,这似乎不必要地复杂。

Excuse my lack of html knowledge, but is it possible to set up a set of say 3 radio buttons so that each one links to a different select list of items?

What I'm trying to do is let the user select either:

Projects select list of all the projects,
Tasks select list of all the tasks,
Users select list of all the users

As far as I have been able to figure from radio buttons so far, they just display text and have a submit value as an input. Is what I'm thinking of infeasible?

I'm kind of hoping there is some plain easy way to link the radio button to each select list, but I can in the worst case imagine just having the appropriate select list place its value into the radio button's value field via a javascript method. That just seems unnecessarily complicated though for what seems like such a simple idea.

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

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

发布评论

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

评论(1

潇烟暮雨 2024-08-19 10:26:12

您肯定需要使用 javascript 来完成此操作;纯 HTML 单选按钮仅用于在表单提交中传输单个值。

为了澄清您的要求,这就是您的想法:

  1. 用户从一组 3 个单选按钮开始,指示他们想要进行哪种类型的选择
  2. 用户选择其中一个按钮
  3. 用户会看到相应类型的选择列表item

如果这就是您的意思,那么最简单的方法就是简单地添加所有三个选择列表,但将它们隐藏。然后向单选按钮添加一个 javascript 事件以显示选定的按钮(并在必要时隐藏其他按钮)。

You would certainly need to use javascript to accomplish this; plain HTML radiobuttons are merely intended to transmit a single value in a form submission.

To clarify what you're asking for, is this what you had in mind:

  1. user starts with set of 3 radio buttons indicating which type of selection they want to make
  2. user selects one of the buttons
  3. user sees a select list for the appropriate type of item

If this is what you mean, the easiest way to do this is to simply add all three select lists, but have them hidden. Then add a javascript event to the radio buttons to show the selected one (and hide the others if necessary).

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