English 中文(简体)
横向和纵向专用单选按钮
原标题:Horizontally and vertically exclusive radio button

我已经使用这个网站很长时间了,从来没有问过我自己的问题。。。提前欢呼。

我有一组“问题”要列出。然后,用户必须将这些问题排列为第一、第二和第三(但问题可能不止三个)。

我遇到的问题是,如果我使单选按钮在一个方向上互斥,用户可以将所有问题列为#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>

In the above example, the value is the question s ID (from the DB)

最佳回答

你必须使用jQuery才能获得这种效果,因为我看不出有什么方法可以用HTML开箱即用下面是一个示例,它给出了所需的效果:

$(document).ready(function() {
    $( :radio ).click(function() {
        $(this).parent().siblings().children( :radio ).attr( checked , false);
    });
});
问题回答

创造性解决方案:

Why don t you use a widget? you could put questions like layers you can drag and move, example:

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

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

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





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签