How can I unify text that take from multiple group radio button?

后端 未结 3 1398
再見小時候
再見小時候 2020-12-04 03:54

My javascript code like this :

$(function(){
    $(\'input[type=\"radio\"]\').click(function(){
        var txt = $(this).parent().text();
        var $radio         


        
3条回答
  •  一个人的身影
    2020-12-04 04:33

    Updated fiddle: https://jsfiddle.net/m7by6zcw/37/

    Basically like Justinas's answer but with the checking/unchecking available.

    The only part I really changed was how the text was being outputted, shown below:

        let output = [];
        $('input[type="radio"]:checked').each( function() {
                var txt = $(this).parent().text();
                output.push(txt);
        });
        $('#result-select').text(output.join(' - '));
    

    You need to reset the data of everything else when something checks:

    $(`input[name=${name}]:not(:checked)`).data('waschecked', false);
    

提交回复
热议问题