Отправляйте три элемента выбора HTML как один для JSON

[D0] все! У меня есть код ниже в моем коде. Я пытаюсь console.log показать {"selectDays":"13","selectMonths":"8","selectYear":"2018"} как формат JSON, но только в одной строке, например: {"dateTimeString:2018/08/13"} в формате «yyyy-mm-dd» это возможно, может кто-то мне помочь?

$(document).ready(function() {
const monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
];
  var qntYears = 4;
  var selectYear = $("#selectYears");
  var selectMonth = $("#selectMonths");
  var selectDay = $("#selectDays");
  var currentYear = new Date().getFullYear();
  
    
  for (var y = 0; y < qntYears; y++){
    let date = new Date(currentYear);
    var yearElem = document.createElement("option");
    yearElem.value = currentYear 
    yearElem.textContent = currentYear;
    selectYear.append(yearElem);
    currentYear--;
  } 

  for (var m = 0; m < 12; m++){
      let monthNum = new Date(2018, m).getMonth();
      let month =  monthNames[monthNum];
      var monthElem = document.createElement("option");
      monthElem.value = monthNum+1; 
      monthElem.textContent = month;
      selectMonth.append(monthElem);
    }

    var d = new Date();
    var month = d.getMonth()+1;
    var year = d.getFullYear();
    var day = d.getDate();

    selectYear.val(year); 
    selectYear.bind("change", AdjustDays);  
    selectMonth.val(month);    
    selectMonth.bind("change", AdjustDays);

    AdjustDays();
    selectDay.val(day);
    
    function AdjustDays(){
      var year = selectYear.val();
      var month = parseInt(selectMonth.val());
      selectDay.empty();
      
      //get the last day, so the number of days in that month
      var days = new Date(year, month, 0).getDate(); 
      
      //lets create the days of that month
      for (var d = 1; d <= days; d++){
        var dayElem = document.createElement("option");
        dayElem.value = d; 
        dayElem.textContent = d;
        selectDay.append(dayElem);
      }
    }    

   var dateTimeString = year + '/' + month +'/' + day;
   console.log(dateTimeString);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="selectDays" name="selectDays"></select>     

<select id="selectMonths" name="selectMonths"></select>

<select  id="selectYears" class="input-year" name="selectYear"></select>

0
задан Bogdan Lozev 13 August 2018 в 13:14
поделиться

1 ответ

Другие вопросы по тегам: