我有一个表单,在不同的组中有多个单选按钮。例如,类别车辆有两个单选按钮
和其他类别一样,有2-2个单选按钮.
我想做的是,当我检查4轮从2轮,我显示一个警告信息弹出,是你一定要切换,如果是,然后好,但不,我想再次检查2轮单选按钮。我也不能这样做,因为我必须在其他领域也这样做。
<input type="radio"/>发布于 2013-12-03 08:34:21
你的问题不太清楚,但据我所知,我猜你想:
$(document).ready(function(){
$('#submit_button').click(function() {
    if (!$("input[@name='radioName']:checked").val()) {
     alert('Nothing is checked!');
    return false;
    }
else {
  alert('One of the radio buttons is checked!');
}
 });
 });并为所有无线电输入添加相同的名称标记:
<input type="radio" name="radioName"/>发布于 2013-12-03 08:43:04
这可能就是你想要达到的目标:
var old_input = $('input[name="wheeler"]:checked');
$('input[name="wheeler"]').change(function(e) {
    console.log(e);
    if (
        old_input.next().text() == '2 Wheeler' &&
        $(this).next().text() == '4 Wheeler'
    ) {
        if (confirm('Are you sure you want to change?')) {
            old_input = $(this);
        }
        else {
            this.checked = 0;
            old_input.get()[0].checked = 1;
        }
    }
    else {
        old_input = $(this);
    }
});http://jsfiddle.net/pQpk7/
发布于 2013-12-03 08:46:22
我认为,当第一次检查单选按钮时,您正在寻找这个http://jsfiddle.net/7rF3d/。当有人检查另一个人时,他首先被提示进行确认。如果用户取消,则将恢复旧的选中无线电。
var lastChecked;
$("input[type=radio]").click(function() {
    if(typeof(lastChecked) != "undefined" && !confirm("are you sure?")) {
        $("input[type=radio]:checked").attr("checked", "false");
        $(lastChecked).prop("checked", true);
    } else {
        lastChecked = $('input[type=radio]:checked');
    }
});https://stackoverflow.com/questions/20345990
复制相似问题