【问题标题】:Have jquery datepicker fill 2 external fields让 jquery datepicker 填充 2 个外部字段
【发布时间】:2016-02-14 17:35:13
【问题描述】:

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

假设我有按钮 A、文本字段 B、文本字段 C。 当您单击按钮 A 时,jquery datepicker 应该会打开。不是在打开的元素中填充值,而是将相同的值插入到 Textfield B 和 Textfield C 中。

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

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

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

【问题讨论】:

  • 您使用的是哪个日期选择器?还请澄清colorpicker 与问题有什么关系并显示相关的html

标签: jquery widget field


【解决方案1】:

好的,我有三个文本框(日期选择器、文本框 B、文本框 C),而不是您要求的(按钮 A、文本字段 B、文本字段 C)。我不认为 jQuery datepicker 可以在您单击按钮时显示,而是将其设置为文本框。但我为你做的一件事是"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" />

【讨论】:

  • 如果是 jQuery UI,datepicker 可以绑定到任何元素,然后使用事件进行更新
  • 如果可能的话,你可以从更改函数中引用元素,其余的都可以
  • 不是真的...change 仅在表单控件上有效
  • 你也可以使用点击功能
  • 点击什么? datepicker API 提供所有需要的事件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多