简体   繁体   English

如何将jquery-ui DATEPICKER插入特定的div中

[英]How to insert a jquery-ui DATEPICKER into a specifec div

I'm using Jquery-UI Datepicker " https://jqueryui.com/datepicker/ " "I'm using it on two inputs" and when I click on an input and choose the date from the calender I want to make an effict on a sibling of the input, but I couldnt because the datepicker is created at the bottom of the html code. 我正在使用Jquery-UI Datepicker“ https://jqueryui.com/datepicker/ ”“我正在两个输入上使用它”,当我单击一个输入并从日历中选择日期时,我想生效在输入的同级上,但我不能,因为datepicker是在html代码的底部创建的。 So I figured that if I could make it be created in the div that has the input I'll be able to control it's siblings. 因此,我认为,如果可以在具有输入的div中创建它,则可以控制它的兄弟姐妹。 So my question is "How I make it be created inside the dive that has the input?" 所以我的问题是“如何在具有输入的潜水中创建它?”


<div class="formss">
  <div class="first-input">
   <input class="input1" id="datepicker1" type="text">
   <span>place holder</span>
  </div>

 <div class="sec-input">
   <input class="input2" id="datepicker2" type="text">
   <span>place holder</span>
  </div>

</div>

JQuery UI Datepicker renders the calendar at the bottom. JQuery UI Datepicker在底部显示日历。 You don't have to worry about it because UI Datepicker provides every option to customize your input. 您不必担心,因为UI Datepicker提供了用于自定义输入的所有选项。 You have calendar instance available. 您有可用的日历实例。 Below is an example, that makes the label of the clicked datepicker field to change color on selecting a date. 下面是一个示例,它使单击的日期选择器字段的标签在选择日期时更改颜色。

$(document).ready(function() {
  $("#datepicker1").datepicker({
    numberOfMonths: 1,
    showButtonPanel: true,
    dateFormat: "yy-mm-dd",
    onSelect: function(date, inst) {
      setTimeout(function() {
       inst.input.siblings().css('color', 'red');
      }, 50);
    }
  });
});

Here inst,input points to the input field which is marked as datepicker field. 在这里inst,input指向标记为日期选择器字段的输入字段。 Hope this helps you. 希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM