我想要一个datepicker按钮,在文本字段中插入所选日期。 我怎样才能做到这一点?
假设我有按钮A,文本字段B,文本字段C. 单击按钮A时,应打开jquery datepicker。而不是填充已打开元素内的值,应将相同的值插入到Textfield B和Textfield C中。
通常你会定义哪个id附加了一个datepicker,如下所示:
$("#datepicker").datepicker();
但是这种逻辑在这种情况下不起作用,因为值应该被填充到不同的字段中。
答案 0 :(得分:1)
好的,我有三个文本框(datepicker,TextboxB,TextboxC),不像你问的那样(按钮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" />