2016-02-14 91 views
1

我想要一個日期選擇器按鈕,在文本字段中插入選定的日期。 我該如何做到這一點?有jquery datepicker填充2外部字段

假設我有按鈕A,Textfield B,Textfield C. 當你點擊按鈕A時,jquery datepicker應該打開。相反,填充所述打開元件內部值的,相同的價值應插入文本字段B和C.文本字段

通常你會定義什麼ID具有連接到這樣的日期選擇器:

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

但這在這種情況下邏輯不起作用,因爲值應填入不同的字段。

+0

您正在使用哪個日期選擇器?也請澄清什麼'colorpicker'與問題和顯示相關的html – charlietfl

回答

1

好吧,在這裏我有三個文本框(日期選擇器,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" />

+0

如果它是jQuery UI的日期選擇器可以綁定到任何元素,然後使用事件來做更新 – charlietfl

+0

如果它可能然後從更改函數您可以引用元素和其餘是好的 – Transformer

+0

以及不是真的......'變化'只對窗體控件有效 – charlietfl