【发布时间】:2013-03-05 12:58:14
【问题描述】:
单击 radiogroup2 中的单选按钮时,所选收音机应与 id='selectedradio' 的收音机交换位置。小提琴http://jsfiddle.net/DCC66/6/ --- 更新 --- 无线电行和代码的清晰视图正在交换但取消http://jsfiddle.net/DCC66/14/
尝试对 id 问题进行排序:http://jsfiddle.net/DCC66/18/
$(".radiogroup2 input[type='radio']").on('click', function () {
$('#radioselected').closest('label').before($(this).closest('label'));
$(this).closest('label').after($('#radioselected').closest('label'));
$(this).attr('domaintype', 'radioselected');
$('radioselected').attr('radioselected', 'domaintype');
});
现在 this:// 交换一次然后停止,然后只是使单击的收音机消失。认为它需要将 id="radioselected" 添加到新交换的收音机中。虽然只更换了收音机,但仍然没有交换。
$(".radiogroup2 input[type='radio']").on('click', function ()
{
$('#radioselected').closest('label').replaceWith($(this).closest('label'));
});
尝试使用克隆仍然没有运气:
$("div.radiogroup2 input[name='domain_ext']").click(function ()
{
$(this).clone('#radioselected').after(this);
});
原创
$("div.radiogroup2 input[name='domain_ext']").click(function()
{
//only if a the radio in radiogroup to are clicked take radio and swap with id='radioselected'
if ($(this).prop('checked'))
{
$(this).after('#radioselected').add(this);
$('#radioselected').after(this);
}
});
因此,在“交换”行中单击的任何无线电都应与第一行中 ID 为“selectedradio”的无线电交换位置
【问题讨论】:
-
你想只交换单选按钮,还是同时交换标签?
-
标签也是如此,整个代码都是针对那个元素的,以防万一用户想要点击其他东西。
标签: javascript jquery jquery-ui jquery-plugins radio-button