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

前端 未结 3 584
[愿得一人]
[愿得一人] 2021-01-16 03:10

My javascript code like this :

$(function(){
    $(\'input[type=\"radio\"]\').click(function(){
        var $radio = $(this);
        var name = $(this).prop         


        
3条回答
  •  [愿得一人]
    2021-01-16 03:18

    You can do:

    var $radioAndCheckboxInputs = $('input:radio, input:checkbox');
    var $resultSelect = $('#result-select');
    $radioAndCheckboxInputs.click(function () {
      var output = [];
      $radioAndCheckboxInputs.filter(':checked').each(function () {
        output.push($(this).parent().text());
      });
      $resultSelect.text(output.join(' - '));
    });
    
    
    • England
    • Spain
    • Italy
    Result

提交回复
热议问题