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

后端 未结 3 1395
再見小時候
再見小時候 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:43

    You have to gather all values from :checked radio buttons, later use .join to convert array to string and place to results field

    $(function(){
        $('input[type="radio"]').click(function(){
          var result = $('#result-select');
          var results = [];
    
          $('input[type="radio"]:checked').each(function () {
            results.push($(this).closest('label').text());
          });
          
          result.text(results.join(' - '));
        });
    });
    
    
    • England
    • Spain
    • Italy
    Result

提交回复
热议问题