让 jquery 日期选择器填充 2 个外部字段

Have jquery datepicker fill 2 external fields

我想要一个日期选择器按钮,用于在文本字段中插入选定的日期。 我怎样才能做到这一点?

假设我有按钮 A、文本域 B、文本域 C。 单击按钮 A 时,jquery 日期选择器应打开。不是在打开的元素中填充值,而是将相同的值插入文本字段 B 和文本字段 C。

通常你会像这样定义附加了日期选择器的 id:

$("#datepicker").datepicker();

但是这个逻辑在这种情况下不起作用,因为值应该填充到不同的字段中。

好的,这里我有三个文本框(datepicker、TextboxB、TextboxC),而不是你问的(按钮 A、文本字段 B、文本字段 C)。我不认为 jQuery 日期选择器可以在您单击按钮时显示,而是将其设为文本框。但是我为你做的一件事是 "Instead of filling the value inside the opened element, the same value shall be inserted into Textfield B and Textfield C."

$(document).ready(function() {
  $("#datepicker").datepicker();
  $("#datepicker").change(function() {
      $("#textboxB, #textboxC").val($(this).val());
  });
  
});
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<input type="text" id="datepicker" placeholder="click me"/>
<input type="text" id="textboxB" />
<input type="text" id="textboxC" />