首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以根据前面的单选按钮限制单选按钮的选择?

是否可以根据前面的单选按钮限制单选按钮的选择?
EN

Stack Overflow用户
提问于 2012-12-05 04:43:52
回答 2查看 951关注 0票数 2

基本上我有一个调查,我希望人们根据重要性对5个项目1-5进行排名。

这是http://jsfiddle.net/madcaesar/jj8ky/

代码语言:javascript
复制
<form>
    <table>
    <tr>
                    <th colspan="2" class="altTH" style="text-align:left">Please rank, in order of most important (1) to least important (5)</th>
                  </tr>
                  <tr>
                    <th><label>Professionalism (promoting the profession of medicine)</label></th>
                    <td>
                        <label style="display:inline"><input type="radio" name="Professionalism" value="1" class="checkbox"/> 1</label>
                        <label style="display:inline"><input type="radio" name="Professionalism" value="2" class="checkbox"/> 2</label>
                        <label style="display:inline"><input type="radio" name="Professionalism" value="3" class="checkbox"/> 3</label>
                        <label style="display:inline"><input type="radio" name="Professionalism" value="4" class="checkbox"/> 4</label>
                        <label style="display:inline"><input type="radio" name="Professionalism" value="5" class="checkbox"/> 5</label>
                    </td>
                  </tr>
                  <tr>
                    <th><label>Government Relations (state and federal government advocacy)</label></th>
                    <td>
                        <label style="display:inline"><input type="radio" name="GovernmentRelations" value="1" class="checkbox"/> 1</label>
                        <label style="display:inline"><input type="radio" name="GovernmentRelations" value="2" class="checkbox"/> 2</label>
                        <label style="display:inline"><input type="radio" name="GovernmentRelations" value="3" class="checkbox"/> 3</label>
                        <label style="display:inline"><input type="radio" name="GovernmentRelations" value="4" class="checkbox"/> 4</label>
                        <label style="display:inline"><input type="radio" name="GovernmentRelations" value="5" class="checkbox"/> 5</label>
                    </td>
                  </tr><tr>
                    <th><label>Education (e.g. CME, staff training, meetings)</label></th>
                    <td>
                        <label style="display:inline"><input type="radio" name="Education" value="1" class="checkbox"/> 1</label>
                        <label style="display:inline"><input type="radio" name="Education" value="2" class="checkbox"/> 2</label>
                        <label style="display:inline"><input type="radio" name="Education" value="3" class="checkbox"/> 3</label>
                        <label style="display:inline"><input type="radio" name="Education" value="4" class="checkbox"/> 4</label>
                        <label style="display:inline"><input type="radio" name="Education" value="5" class="checkbox"/> 5</label>
                    </td>
                  </tr>
                  <tr>
                    <th><label>Regulatory and legal analysis and support</label></th>
                    <td>
                        <label style="display:inline"><input type="radio" name="Regulatory" value="1" class="checkbox"/> 1</label>
                        <label style="display:inline"><input type="radio" name="Regulatory" value="2" class="checkbox"/> 2</label>
                        <label style="display:inline"><input type="radio" name="Regulatory" value="3" class="checkbox"/> 3</label>
                        <label style="display:inline"><input type="radio" name="Regulatory" value="4" class="checkbox"/> 4</label>
                        <label style="display:inline"><input type="radio" name="Regulatory" value="5" class="checkbox"/> 5</label>
                    </td>
                  </tr>
                  <tr>
                    <th><label>Communications (Iowa Medicine magazine, website, media relations, etc.)</label></th>
                    <td>
                        <label style="display:inline"><input type="radio" name="Communications" value="1" class="checkbox"/> 1</label>
                        <label style="display:inline"><input type="radio" name="Communications" value="2" class="checkbox"/> 2</label>
                        <label style="display:inline"><input type="radio" name="Communications" value="3" class="checkbox"/> 3</label>
                        <label style="display:inline"><input type="radio" name="Communications" value="4" class="checkbox"/> 4</label>
                        <label style="display:inline"><input type="radio" name="Communications" value="5" class="checkbox"/> 5</label>
                    </td>
                  </tr>

</table>

</form>

是否可以使用jQuery在选择%1后使%1不可用?和2,一旦选择了2,依此类推?现在他们可以选择他们想要的任何数字,而我想不出一个方法来做到这一点。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-05 04:56:42

如果您选择了某个数字,它将取消选择具有相同值的任何其他数字,这样的情况会如何呢?

http://jsfiddle.net/jj8ky/2/

代码语言:javascript
复制
$("#radio_table").on("click", ".checkbox", function () {
    var $this = $(this);
    var all = $("#radio_table").find(".checkbox").not($this);
    var val = $this.val();

    if ($this.prop("checked") === true) {
        all.filter(function () {
            return $(this).val() === val;
        }).prop("checked", false);
    }
});
票数 3
EN

Stack Overflow用户

发布于 2012-12-05 04:50:40

您可以在需要时禁用某些无线电:例如

代码语言:javascript
复制
if($("#radio").val()==2) $("#otherRadio").attr("disabled",true);
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13711542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档