Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 如何使两个同名单选按钮块在HTML中分离?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何使两个同名单选按钮块在HTML中分离?

Javascript 如何使两个同名单选按钮块在HTML中分离?,javascript,jquery,html,Javascript,Jquery,Html,我需要为我的项目使用两个单选按钮块,其中我将值存储在数据库中,并且根据HTML表单中的另一个结果显示一个单选按钮块或另一个单选按钮块 问题是,如果我对所有选项使用相同的名称,它们都属于同一组,这是我不想要的 我只是想尝试一下,问问有没有办法把它分成不同的块,用相同的名字,这可能吗 这是我的 和mi代码: <fieldset data-role="controlgroup" data-type="horizontal" > <legend>Negotiated:&l

我需要为我的项目使用两个单选按钮块,其中我将值存储在数据库中,并且根据HTML表单中的另一个结果显示一个单选按钮块或另一个单选按钮块

问题是,如果我对所有选项使用相同的名称,它们都属于同一组,这是我不想要的

我只是想尝试一下,问问有没有办法把它分成不同的块,用相同的名字,这可能吗

这是我的

和mi代码:

<fieldset data-role="controlgroup" data-type="horizontal" >
    <legend>Negotiated:</legend>
    <input type="radio" name="radio-view" id="radio-view-a" value="0" checked="checked" />
    <label for="radio-view-a">No</label>
    <input type="radio" name="radio-view" id="radio-view-b" value="1" />
    <label for="radio-view-b">Yes</label>
</fieldset>


<fieldset data-role="controlgroup" data-type="horizontal" >
    <legend>Negotiated:</legend>
    <input type="radio" name="radio-view" id="radio-view-a1" value="0" />
    <label for="radio-view-a1">No</label>
    <input type="radio" name="radio-view" id="radio-view-b1" value="1" checked="checked" />
    <label for="radio-view-b1">Yes</label>
</fieldset>

协商:
不
对
协商:
不
对

如果你给他们相同的类,你的问题很容易解决。将代码更改为:

<fieldset data-role="controlgroup" data-type="horizontal" >
<legend>Negotiated:</legend>
<input type="radio" name="radio-view1" class="radio-view" id="radio-view-a" value="0" checked="checked" />
<label for="radio-view-a">No</label>
<input type="radio" name="radio-view1" class="radio-view" id="radio-view-b" value="1" />
<label for="radio-view-b">Yes</label>
</fieldset>


<fieldset data-role="controlgroup" data-type="horizontal" >
<legend>Negotiated:</legend>
<input type="radio" name="radio-view2" class="radio-view" id="radio-view-a1" value="0" />
<label for="radio-view-a1">No</label>
<input type="radio" name = "radio-view2" class="radio-view" id="radio-view-b1" value="1" checked="checked" />
<label for="radio-view-b1">Yes</label>
</fieldset>

在第二种方法中,可以使用前缀为
data-
的任何属性。例如,您还可以使用
数据myclass

但不包括大写字母,它们是不允许的。如果您使用的是任何框架,如
jquerymobile
,则不要使用其保留的
数据-
属性,如
数据角色
。在属性前面加上“my”是一种很好的做法,例如,
datamyclass


不可能使用相同的名称。您需要为不同的组指定不同的名称。您可以为它们指定相同的
类,而不是为它们指定相同的
id
。请参阅以供参考。非常欢迎@SaulOrtega:)每组的名称不同。收音机-VIEW 1和收音机-view2@SaulOrtega名称不能相同。如果我没有误解的话,您希望给所有表单元素一个标识,以便您可以在JavaScript中引用它们。这也可以通过类来完成。只需使用
document.getElementsByClassName(“无线电视图”)。我真的看不出任何其他理由让所有元素都具有相同的
名称,如果还有其他理由,请告诉我。如果没有,我想你应该接受这个答案。谢谢你的回答,Arjun,但我需要的是让它们具有相同的名称,这样当我将它们的值放入它们的数据库时。我使用的平台将查找具有该特定名称的元素,如果该元素具有不同的名称,它将尝试将其放在DB中我不想要的另一个字段中。@SaulOrtega不幸的是,据我所知,这是不可能的。“很抱歉,我不能也不能帮助你。”索洛特加我希望其他人能帮助你。
<fieldset data-role="controlgroup" data-type="horizontal" >
<legend>Negotiated:</legend>
<input type="radio" name="radio-view1" data-customclass="radio-view" id="radio-view-a" value="0" checked="checked" />
<label for="radio-view-a">No</label>
<input type="radio" name="radio-view1" data-customclass="radio-view" id="radio-view-b" value="1" />
<label for="radio-view-b">Yes</label>
</fieldset>


<fieldset data-role="controlgroup" data-type="horizontal" >
<legend>Negotiated:</legend>
<input type="radio" name="radio-view2" data-customclass="radio-view" id="radio-view-a1" value="0" />
<label for="radio-view-a1">No</label>
<input type="radio" name="radio-view2" data-customclass="radio-view" id="radio-view-b1" value="1" checked="checked" />
<label for="radio-view-b1">Yes</label>
</fieldset>