如何通过单击选项而不是实际按钮本身来选择单选按钮

how to select a radio button by clicking on an option and not the actual button itself

本文关键字:按钮 单选按钮 选择 单击 何通过 选项      更新时间:2023-09-26

假设我有以下三个选项,每个选项旁边都有一个单选按钮

  • 伦敦
  • 纽约
  • 迪拜

我需要jQuery,当用户单击单选按钮选择的单词时!

这是HTML中的内置功能,因此不需要JavaScript。只需像这样使用 label 标记:

<label><input type="radio"> London</label>
<label><input type="radio"> New York</label>
<label><input type="radio"> Dubai</label>

两种方式:

  1. <label for="london"><input type="radio" id="london"> London</label> .

使用类似于labelfor属性 radioid

  1. <label><input type="radio" > London</label>

radio放在label内。

非常基本的HTML

您可以使用标签标签:

<input id="emptyacct" type="radio" name="account" value="radiobutton" />
<label for="emptyacct">Yes </label>

这只是HTML;)

<input id="input_london" type="radio" name="london" value="radiobutton" />
<label for="input_london">London</label>
<input id="input_ny" type="radio" name="ny" value="radiobutton" />
<label for="input_ny">New York</label>
...