繁体   English   中英

单击复选框获取单选按钮的值

[英]Checkbox on click get value of radio button

所有,

我有这个设置。 现在它需要修改。

  1. 当页面首次加载时,预先选择其中一个单选按钮,例如。 全部遇见或全部未遇到或全部错过。 现在,所有Met按钮都被选中。
  2. 所有单选按钮都被禁用。 选中该复选框后,应仅在文本区域中填充行ID,选中该行的单选按钮的值。(部分工作)
  3. 如果取消选中该复选框,则需要删除先前选中复选框时填充的值。(不起作用)
  4. 如果用户选择了另一个单选按钮(选中复选框后),则需要更新该值。(Works)
  5. 此外,当选择缺少单选按钮时,显示文本字段并且需要更新输入的值。 (引发未定义)

我做了很多但是事情没有用。

大师可以帮助,再次非常感激吗?

在这里小提琴

$("input:radio").hover(function () {
$(this).prev('.r-title').show();
 }, function () {
if (!$(this).is(':checked')) {
    $(this).siblings('.r-title, .m-notes').hide();
}
 });

//Radio Buttons

$("input:radio").click(function () {
$(this).parent().parent().find('.r-title, .m-notes').hide();
var totalRd = $('table').find('input:radio:checked').length;
var clicked = [];
$("#totalRd .rd-count").html(totalRd); //Counts the radio buttons clicked
$(this).siblings('.r-title, .m-notes').show();
$('table').find("input[type=radio]:checked").each(function () {
var selectedId = $(this).parent().parent().attr('id');
var newVal = ($(this).next('.m-notes:visible').length) ? this.value + "~" +                $(this).next('.m-notes:visible').val() : this.value;
clicked.push(selectedId + "~" + newVal);
 }); //checked
$("#inputhere").val(clicked.join('|'));
});

//Input Field for Missing Radio Button

$('.m-notes').keyup(function () {
var $self = $(this);
var clicked = [];
$('table').find("input[type=radio]:checked").each(function () {
    var selectedId = $(this).parent().parent().attr('id');
    var newVal =  this.value + "~" + $(this).next('.m-notes').val();
    clicked.push(selectedId + "~" + newVal);
}); //checked
$("#inputhere").val(clicked.join('|'));
});

//CheckBox
var clicked=[];
$("input:checkbox").change(function(){
$(this).parent().parent().find("input[type=radio]").prop('disabled',!this.checked);
});

使用此功能,您可以在选中/取消选中复选框中获取所选无线电的值:

$("input:checkbox").change(function(){
    $(this).parent().parent().find("input[type=radio]").prop('disabled',!this.checked);

    $("#inputhere").val("");
    $(".chkBx").each(function(){
        if($(this).prop("checked")){
            var txtVal = $(this).parents("div").eq(1).find("input[type='radio']:checked").val();
            var idRowVal = $(this).parents("div").eq(1).attr("id");
            var textboxPrevValue = $("#inputhere").val();
            var textAndIdVal = textboxPrevValue + txtVal + " " +  idRowVal + " ";
            $("#inputhere").val(textAndIdVal);
        }
    });

});

小提琴

你必须在你的条件下添加它

$(this).parents("div").eq(1).find("input[type='radio']").val();//add this

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM