显示基于php中特定日期名称的radiobutton

时间:2018-05-07 08:13:16

标签: javascript php jquery mysql

我正在尝试根据文本框中选择的特定日期名称显示单选按钮。我创建了一个表日,它存储了日期名称和描述。当您从日期选择器中选择日期时,它会提取日期名称,并根据我想要获取的日期名称值,选择日期名称值。例如,如果所选日期是13-05-2018,则它将显示日期为太阳,在太阳上显示在单选按钮上的事件或动态选择选项。 这是代码。

  $(function() {
  var date = new Date();
  var dayNo = date.getDay();
  var mindate = (7 - dayNo);
  var d = ['sun', 'mon', 'tue', 'wed', 'th', 'fr', 'sat'];
  var event = ['test1', 'Test2']
var event1 = ['test2', 'Test2']
  //Lest assume this is  event from database
  $("#datepicker").datepicker({
    dateFormat: 'yy-mm-dd',
    firstDay: 1,
    minDate: mindate,
    onSelect: function(dateText, inst) {
      var today = new Date(dateText);
      var a = (d[today.getDay()]);
      $('#slDay').val(d[today.getDay()])
      var html = '';
      $('#slDay').html('');
     if ((d[today.getDay()] =='sun'){
      $.each(event, function(index, value) {

        html += '<option value="' + value + '">' + value + '</option>'
      });

});           $(&#39;#slDay&#39)。追加(HTML);

    });
  });
});
</script>

<input type="text" id="datepicker">
<input type="text" id="datepicker1" name="datepicker1">

1 个答案:

答案 0 :(得分:0)

使用dropdown id和append.I为选项

创建代码段

$(function() {
  var date = new Date();
  var dayNo = date.getDay();
  var mindate = (7 - dayNo);
  var d = ['sun', 'mon', 'tue', 'wed', 'th', 'fr', 'sat'];
  var event = ['test1', 'Test2'] //Lest assume this is  event from database
  $("#datepicker").datepicker({
    dateFormat: 'yy-mm-dd',
    firstDay: 1,
    minDate: mindate,
    onSelect: function(dateText, inst) {
      var today = new Date(dateText);
      var a = (d[today.getDay()]);
      $('#slDay').val(d[today.getDay()])
      var html = '';
      $('#slDay').html('');
      if (d[today.getDay()] == 'sun')
        $.each(event, function(index, value) {
          html += '<option value="' + value + '">' + value + '</option>'
        });
      $('#slDay').append(html);
    }

  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<input type="text" id="datepicker">

<select id='slDay'>

</select>