如何在每个选择选项上使用jQuery获取每个跨度数据?

时间:2018-07-09 12:42:37

标签: jquery

我只想使用jQuery来获取html <p>标记数据,但仅会获取前两个<p>数据,而不接收其他数据,我为此使用的代码是:< / p>

<div id="perDayScheduleForm">
  <select class="select_day" id="perday">
    <option>Select day</option>
    <option>Sunday</option>
    <option>Monday</option>
    <option>Tuesday</option>
    <option>Wednesday</option>
    <option>Thursday</option>
    <option>Friday</option>
    <option>Saturday</option>
  </select>
  <div id="bookingtime">
  </div>
  <div id="buttons">
    <button id="save">Save</button>
  </div>
</div>
else if (this.id == 'perDaySchedule') {
  $('#setScheduleForm').hide();
  $('#perDayScheduleForm').show();
  var valueSelected;
  $('#perday').change(function(e) {
    $('#bookingtime').empty();
    var optionSelected = $("option:selected", this);
    valueSelected = this.value;
    $.ajax({
      url: "/api/v1/spots",
      type: "GET",
      data: {
        day: valueSelected
      },
      dataType: "json",
      success: function(response) {
        $('#save').hide();
        if (response.response.data != null) {
          console.log(response.response.data)
          $('#bookingtime').append('<h3>Booking spots avaliable by admin</h3>');
          for (var i = 0; i < response.response.data.length; i++) {
            $('#bookingtime').append('<p id=' + response.response.data[i]._id + ' style="display:inline-block;">' + convertTime24to12(secondsTimeSpanToHMS(response.response.data[i].start_time + 19800)) + " - " + convertTime24to12(secondsTimeSpanToHMS(response.response.data[i].end_time + 19800)) + '</p><select id="select_count' + response.response.data[i]._id + '"></select><br>')
          }
          var optionsArr = $('#bookingtime').map(function() {
            return $(this).find('select').length;
          }).toArray();
          for (var i = 1; i <= optionsArr; i++) {
            console.log(i);
            var numbers = [1, 2, 3, 4, 5];
            for (var j = 0; j < numbers.length; j++) {
              $('<option/>').val(numbers[j]).html(numbers[j]).appendTo('select[id^=select_count]');
            }
          }
          $('#save').show();
        }
      }
    });
  });
  $('#save').on('click', function() {
        var span_arr = [];
        var optionsArr = $('#bookingtime').map(function() {
          return $(this).find('select').length;
        }).toArray();
        for (var i = 1; i <= optionsArr; i++) {
          span_arr.push({
            day: valueSelected,
            time_slug: i,
            timing: $("#" + i).text(),
            count: parseInt($('select[id^=select_count]').val())
          });
        }

图片:-

当我单击“星期天”然后在“星期天”时,将获取p标签数据,但在其他日子里,它将不获取p标签{在显示代码时,id标签中的{1}}会动态给出。

每天如何更改p标签离子的数据?

0 个答案:

没有答案