首页 文章

水平和垂直专用单选按钮

提问于
浏览
1

多年来一直在使用这个网站,从来没有去过问自己的问题...提前喝彩 .

我有一组要列出的“问题” . 然后,用户必须将这些问题排在第1,第2和第3(但可能会有超过3个问题) .

我遇到的问题是,如果我将单选按钮在一个方向上互斥 - 用户可以将所有问题排在第2位,但是如果我将它们排在另一个方向,则用户可以将相同的问题排在第一位 . 1,#2,和#3 .

有没有办法(可能使用jquery / Jscript)使单选按钮在两个方向上互斥?

例:

<table>
<tr>
    <th>Question</th><th>Rank #1</th><th>Rank #2</th><th>Rank #3</th>
</tr><tr>
    <td>QUESTION 1</td>
    <td><input type="radio" name="rank1" value="1" id="1_1" /></td>
    <td><input type="radio" name="rank2" value="1" id="1_2" /></td>
    <td><input type="radio" name="rank3" value="1" id="1_3" /></td>
</tr><tr>
    <td>QUESTION 2</td>
    <td><input type="radio" name="rank1" value="3" id="3_1" /></td>
    <td><input type="radio" name="rank2" value="3" id="3_2" /></td>
    <td><input type="radio" name="rank3" value="3" id="3_3" /></td>
</tr>

在上面的例子中,值是问题的ID(来自DB)

2 回答

  • 2

    您将不得不使用jQuery来实现此效果,因为我无法看到它与HTML一起开箱即用的方式 . Here is an example给出了预期的效果:

    $(document).ready(function() {
        $(':radio').click(function() {
            $(this).parent().siblings().children(':radio').attr('checked', false);
        });
    });
    
  • 4

    Creative solution:

    你为什么不用小工具?你可以提出像你可以拖动和移动的图层之类的问题,例如:

    http://jqueryui.com/demos/sortable/

    http://jqueryui.com/demos/draggable/#sortable

    第一个出现的将是第一个 .

相关问题