2013-07-12 9 views
0

我使用jQuery標籤http://jqueryui.com/tabs/我怎樣才能事後添加JavaScript-的DateTimePicker?

自定義一些選項後,用戶單擊按鈕並重新加載標籤。

function refresher() { 
     //empty the tab 
     $("#tabs-individually").empty(); 

      //load new stuff 
     //put the container for highcharts-chart in the tab 
     $("#tabs-individually").append('<table><tr><td align="left"><form id="formrange">from<input type="text" size="20" id="startdate"/>to<input type="text" size="20" id="enddate" /><select id="range" ><option value="second">second</option><option value="minute" selected>minute</option><option value="hour" >hour</option><option value="day" >day</option></select><input id="button" type="button" value="confirm" onclick="redraw()" /></form></td></tr><tr><td><div id="container"></td></tr></div>');  

我的問題是jQuery datetimepicker Addon。重新加載標籤後,有2個輸入字段,應該通過JavaScript獲得一個DateTimePicker。最後,它應該是這樣的:

我怎樣才能改變我的JavaScript代碼,以便它加載後的標籤是空的?

/* 
    <script type="text/javascript"> 
    $("#startdate").datetimepicker({ showSecond: true, timeFormat: 'HH:mm:ss', }); 
    $("#enddate").datetimepicker({ showSecond: true, timeFormat: 'HH:mm:ss', }); 
    </script> 
    */ 

enter image description here

回答

1

您需要的頁面刷新後,重新初始化輸入元素的日期選擇控件。

function refresher() { 
    //empty the tab 
    $("#tabs-individually").empty(); 

    //load new stuff 
    //put the container for highcharts-chart in the tab 
    var el = $('<table><tr><td align="left"><form id="formrange">from<input type="text" size="20" id="startdate"/>to<input type="text" size="20" id="enddate" /><select id="range" ><option value="second">second</option><option value="minute" selected>minute</option><option value="hour" >hour</option><option value="day" >day</option></select><input id="button" type="button" value="confirm" onclick="redraw()" /></form></td></tr><tr><td><div id="container"></td></tr></div>').appendTo("#tabs-individually"); 
    $('#startdate, #enddate').datepicker({}); 
} 
+0

@ Susanne92我添加了一個樣本 –

+0

謝謝!有用!我應該減少我的問題...這很簡單...對不起 – Susanne92

0

可以使用on功能,然後刪除datetimepicker線:

$(document).ready(function() { 
    $("#tabs-individually").on("load", "#startdate, #enddate", function() { 
     $(this).datetimepicker({ showSecond: true, timeFormat: 'HH:mm:ss', }); 
    }); 
}