Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单选按钮在标签内使用时出现故障_Javascript_Html_Radio Button_Radiobuttonlist - Fatal编程技术网

Javascript 单选按钮在标签内使用时出现故障

Javascript 单选按钮在标签内使用时出现故障,javascript,html,radio-button,radiobuttonlist,Javascript,Html,Radio Button,Radiobuttonlist,我正在研究html和CSS。我必须在我的页面中添加5个单选按钮,并且在标签中添加了这些按钮。但是当我寻找页面时。它显示所有选中的单选按钮,而且我无法取消选中。问题是我一次只需要选择一个单选按钮。这是我的密码 <label class="radio"><input type="radio"> Pepse</label> <label class="radio"><input type="radio"> Coke</label>

我正在研究html和CSS。我必须在我的页面中添加5个单选按钮,并且在
标签中添加了这些按钮。但是当我寻找页面时。它显示所有选中的单选按钮,而且我无法取消选中。问题是我一次只需要选择一个单选按钮。这是我的密码

<label class="radio"><input type="radio"> Pepse</label> 
<label class="radio"><input type="radio"> Coke</label> 
<label class="radio"><input type="radio">Mirinda</label>
<label class="radio"><input type="radio">Maaza </label>
百事可乐
焦炭
米林达
马扎

单选按钮需要通用名称。如果不给它们一个
名称
属性,每个单选按钮实际上都会变成一个单向复选框。您可以选择它们,但不能取消选择它们

<input type="radio" name="foo" value="1" />
<input type="radio" name="foo" value="2" />

<input type="radio" value="3" />


在这种情况下,两个
foo
单选按钮将在内部链接,因为它们的名称相同,但值为
3
的单选按钮将完全独立,并与您的相同。

单选按钮需要通用名称。如果不给它们一个
名称
属性,每个单选按钮实际上都会变成一个单向复选框。您可以选择它们,但不能取消选择它们

<input type="radio" name="foo" value="1" />
<input type="radio" name="foo" value="2" />

<input type="radio" value="3" />

在这种情况下,两个
foo
单选按钮将在内部链接,因为它们的名称相同,但值为
3
的按钮将完全独立,并与您的按钮相同。

添加组名

百事可乐
焦炭
米林达
马扎
牛奶起泡剂
添加组名

百事可乐
焦炭
米林达
马扎
牛奶起泡剂

1.一组收音机需要一个名称,以便浏览器知道选择了哪个

2.如果要将标签置于输入之外,可以使用for属性 告诉浏览器此标签适用于具有相同id的收音机

<label for="a">a</label>
<input type="radio" name="aname" id="a" value="a"><br>
<label for="b">b</label>
<input type="radio" name="aname" id="b" value="b"><br>
<label for="c">c</label>
<input type="radio" name="aname" id="c" value="c"><br>
<label for="d">d</label>
<input type="radio" name="aname" id="d" value="d"><br>
a

B
C
D
但我也更喜欢标签内的收音机,所以

<label><input type="radio" name="aname" value="a">a</label><br>
<label><input type="radio" name="aname" value="b">b</label><br>
<label><input type="radio" name="aname" value="c">c</label><br>
<label><input type="radio" name="aname" value="d">d</label><br>
<label><input type="radio" name="aname" value="e">e</label><br>
a
b
c
d
e
3.通常情况下,他们也需要一个值,但使用js的ur除外

<label><input type="radio" name="aname">a</label><br>
<script>
document.write(document.getElementsByTagName('label')[0].childNodes[1].nodeValue)
</script>
a
document.write(document.getElementsByTagName('label')[0].childNodes[1].nodeValue)


1之后写入。一组收音机需要一个名称,以便浏览器知道选择了哪个

2.如果要将标签置于输入之外,可以使用for属性 告诉浏览器此标签适用于具有相同id的收音机

<label for="a">a</label>
<input type="radio" name="aname" id="a" value="a"><br>
<label for="b">b</label>
<input type="radio" name="aname" id="b" value="b"><br>
<label for="c">c</label>
<input type="radio" name="aname" id="c" value="c"><br>
<label for="d">d</label>
<input type="radio" name="aname" id="d" value="d"><br>
a

B
C
D
但我也更喜欢标签内的收音机,所以

<label><input type="radio" name="aname" value="a">a</label><br>
<label><input type="radio" name="aname" value="b">b</label><br>
<label><input type="radio" name="aname" value="c">c</label><br>
<label><input type="radio" name="aname" value="d">d</label><br>
<label><input type="radio" name="aname" value="e">e</label><br>
a
b
c
d
e
3.通常情况下,他们也需要一个值,但使用js的ur除外

<label><input type="radio" name="aname">a</label><br>
<script>
document.write(document.getElementsByTagName('label')[0].childNodes[1].nodeValue)
</script>
a
document.write(document.getElementsByTagName('label')[0].childNodes[1].nodeValue)

马克B写了一篇精彩的文章。有人说你是天才吗。它工作得很好。非常感谢你这个令人振奋的事实。太棒了,马克B。有人说你是天才吗。它工作得很好。非常感谢你这一激动人心的事实。