Javascript 如何在表单上保持选中多个单选按钮
下面是我的代码Javascript 如何在表单上保持选中多个单选按钮,javascript,jquery,html,css,Javascript,Jquery,Html,Css,下面是我的代码 <div class="filter_client_search_container"> <div class="filter_search_box" style="margin-top:15px;float:left;margin-right:5px;width:349px;"> <div class="filter_field"> <input type="radio" id="allindividuals
<div class="filter_client_search_container">
<div class="filter_search_box" style="margin-top:15px;float:left;margin-right:5px;width:349px;">
<div class="filter_field">
<input type="radio" id="allindividuals" name="clienttype">
<label for="allindividuals" style="width:260px">All Individuals</label>
</div>
<div class="filter_field">
<input type="radio" id="byindividual" name="clienttype">
<label for="byindividual" style="width:146px;">By Individual Name</label>
<input type="text" name="clientcriteria">
</div>
<div class="filter_search_criteria" style="left:186px;">
<input type="button" name="APPLY" value="Apply">
</div>
</div>
<div class="filter_search_box" style="margin-top:15px;float:left;width:352px;margin-right:5px;">
<div class="filter_field">
<input type="radio" id="allcompanies" name="clienttype" value="allclients" checked>
<label for="allcompanies" style="width:260px;">All Companies</label>
</div>
<div class="filter_field">
<input type="radio" id="bycompany" name="clienttype" value="byclient">
<label for="bycompany" style="width:149px;">By Company Name</label>
<input type="text" name="byclientcriteria">
</div>
<div class="filter_search_criteria" style="left:189px;">
<input type="button" name="APPLY" value="Apply">
</div>
</div>
</div>
所有个人
以个人名义
所有公司
按公司名称
我在这里得到的是“filter\u client\u search\u container”div,它包含两个filter search box div。每个filter search box都有自己的几个单选按钮,我想要的是,我应该能够在第一个filter search box中选中一个单选按钮,然后在第二个过滤器搜索框中选中另一个。但是我只允许有一个单选按钮来检查一个页面,所以我不能有多个单选按钮检查
但是为什么我不能用这种方法来完成呢。。。我原以为这两个过滤搜索框会使单选按钮相互独立
有什么想法吗?单选按钮通过
name
属性链接。在所有name=“clienttype”
单选按钮中,您只能选择1。如果要选择多个,请将其更改为复选框,或更改名称值
在重新阅读您的帖子后,您需要做的似乎是为一个分区中的单选按钮指定相同的名称,然后为另一个分区中的单选按钮指定不同的名称。例如,类似以下内容:
<div class="filter_client_search_container">
<div class="filter_search_box" style="margin-top:15px;float:left;margin-right:5px;width:349px;">
<div class="filter_field">
<input type="radio" id="allindividuals" name="clienttype1">
<label for="allindividuals" style="width:260px">All Individuals</label>
</div>
<div class="filter_field">
<input type="radio" id="byindividual" name="clienttype1">
<label for="byindividual" style="width:146px;">By Individual Name</label>
<input type="text" name="clientcriteria">
</div>
<div class="filter_search_criteria" style="left:186px;">
<input type="button" name="APPLY" value="Apply">
</div>
</div>
<div class="filter_search_box" style="margin-top:15px;float:left;width:352px;margin-right:5px;">
<div class="filter_field">
<input type="radio" id="allcompanies" name="clienttype2" value="allclients" checked>
<label for="allcompanies" style="width:260px;">All Companies</label>
</div>
<div class="filter_field">
<input type="radio" id="bycompany" name="clienttype2" value="byclient">
<label for="bycompany" style="width:149px;">By Company Name</label>
<input type="text" name="byclientcriteria">
</div>
<div class="filter_search_criteria" style="left:189px;">
<input type="button" name="APPLY" value="Apply">
</div>
</div>
</div>
所有个人
以个人名义
所有公司
按公司名称
请注意
名称
属性中的差异。单选按钮由名称
属性链接。在所有name=“clienttype”
单选按钮中,您只能选择1。如果要选择多个,请将其更改为复选框,或更改名称值
在重新阅读您的帖子后,您需要做的似乎是为一个分区中的单选按钮指定相同的名称,然后为另一个分区中的单选按钮指定不同的名称。例如,类似以下内容:
<div class="filter_client_search_container">
<div class="filter_search_box" style="margin-top:15px;float:left;margin-right:5px;width:349px;">
<div class="filter_field">
<input type="radio" id="allindividuals" name="clienttype1">
<label for="allindividuals" style="width:260px">All Individuals</label>
</div>
<div class="filter_field">
<input type="radio" id="byindividual" name="clienttype1">
<label for="byindividual" style="width:146px;">By Individual Name</label>
<input type="text" name="clientcriteria">
</div>
<div class="filter_search_criteria" style="left:186px;">
<input type="button" name="APPLY" value="Apply">
</div>
</div>
<div class="filter_search_box" style="margin-top:15px;float:left;width:352px;margin-right:5px;">
<div class="filter_field">
<input type="radio" id="allcompanies" name="clienttype2" value="allclients" checked>
<label for="allcompanies" style="width:260px;">All Companies</label>
</div>
<div class="filter_field">
<input type="radio" id="bycompany" name="clienttype2" value="byclient">
<label for="bycompany" style="width:149px;">By Company Name</label>
<input type="text" name="byclientcriteria">
</div>
<div class="filter_search_criteria" style="left:189px;">
<input type="button" name="APPLY" value="Apply">
</div>
</div>
</div>
所有个人
以个人名义
所有公司
按公司名称
请注意
name
属性中的差异。单选按钮只选择一个值,正如Dryden所说,共享name=“clienttype”的单选按钮将共享选择,并且只有一个可以激活,因此,请更改name属性,或者如果您想选择多个选项,最好使用复选框。单选按钮只选择一个值,正如Dryden所说,共享name=“clienttype”的单选按钮将共享选择,并且只有一个可以激活,因此,请更改“名称”属性,或者如果您想要多选,最好使用复选框。谢谢Dryden!这正是单选按钮的渴望行为,我需要让它们在我的项目中工作。谢谢!!谢谢德莱顿!这正是单选按钮的渴望行为,我需要让它们在我的项目中工作。谢谢!!谢谢你,科罗内克斯。这里的小费很棒!谢谢你,科罗内克斯。这里的小费很棒!