2015-02-05 77 views
0

我有一個使用.append動態創建的輸入字段,所以這意味着我必須通過將onClick函數添加到字段來調用datepicker。它看起來像這樣:如何將dateFormat選項設置爲jQuery datepicker,何時調用onClick?

<input class="myclass" name="myfield" type="text" id="myfield" onclick="$(\'#myfield\').datepicker();$(\'#myfield\').datepicker(\'show\');"> 

什麼是添加這個功能裏面dateFormat選項中正確的方法是什麼?

我想:

<input class="myclass" name="myfield" type="text" id="myfield" onclick="$(\'#myfield\').datepicker();$(\'#myfield\').datepicker(\'"show", "option", "dateFormat", "yy-mm-dd"\');"> 

,但我得到ILLEGAL

回答

1

做一些挖掘,我發現我的答案後。這裏演示:

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script> 
 

 
<input name="puDate1" type="text" id="puDate1" onclick="$(this).datepicker({ dateFormat: 'mm/dd' }).datepicker('show');" placeholder="Date" >

相關問題