2016-07-23 85 views
0

我已經經歷了jQuery的文檔搜索,以及hereherehere,但似乎無法找到爲什麼這是行不通的。我在燃氣HTML文件中有這樣的:如何在GAS中使用HTMLService將默認日期添加到jQuery datepicker?

<!DOCTYPE html> 
    <html> 
    <head> 
    <base target="_top"> 
    </head> 
    <body> 
<form> 
<p> 
    Name:<input type="text" name="firstname"><br> 
    Start Date:<input type="date" id="startDate" name="startDate"> 
    time:<input type="time" name="startTime"><br> 
    End Date:<input type="date" id="endDate" name="endDate"> 
    time:<input type="time" name="endTime"><br> 
    <input value="Process" type="submit"> 
</p> 
</form> 
</body> 
<?!= include('stylesheet'); ?> 
<?!= include('javascript'); ?> 
</html> 

,這在javascript.html文件以及:

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jqueryui.min.js"> 

$(function() { //meant to run on load 
    $("#startDate").datepicker(
    { 
    defaultDate: +14 //14 days from now 
    } 
); 
}); 
</script> 

它的工作原理,如果我在的startDate輸入的標籤添加默認的日期,但我無法弄清楚爲什麼我的默認日期不會加載。想法?

+0

什麼不起作用? '+14 === 14',也許你想要''+ 14''? – Musa

+0

我已測試添加任何內容到此行,例如'defaultDate:'2016-08-01''沒有結果。 –

+0

它確實有效,但不是我想的。在將'type'更改爲'text'並使用以下內容後,我將設置日期。我以爲defaultDate也做到了這一點,但現在我知道了。 '' –

回答

1

我相信你的JavaScript代碼沒有運行,因爲你沒有關閉和打開<script>標籤,試試這個在您的javascript.html文件:

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jqueryui.min.js"></script> 
<script> 
$(function() { //meant to run on load 
    alert("It's running :D"); 

    $("#startDate").datepicker(
    { 
    defaultDate: +2 
    } 
); 
}); 
</script> 

另外,不要忘了包括jQuery的CDN :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
相關問題