2016-07-15 65 views
0

我在我的一個頁面上有一個日期選擇器,它有一個文本框,一個點擊查看日曆的按鈕和一個提交按鈕。當我點擊按鈕查看日曆時,我可以選擇日期並在文本框中顯示。不過,我還希望能夠在框內點擊以查看日曆,但當我點擊框時目前沒有任何反應。下面是代碼(目前在頭部分,但我打算讓外部更高版本):DatePicker從文本框中查看日曆

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script> 
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" /> 
<script type="text/javascript"> 
    $(function() { 
     $("[id$=TextBox1]").datepicker({ 
      showOn: 'button', 
      buttonImageOnly: true, 
      buttonImage: 'http://jqueryui.com/demos/datepicker/images/calendar.gif' 
     }); 
    }); 
</script> 

這裏是文本框:

<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"></asp:TextBox> 
<asp:Button ID="btnSave" runat="server" Text="Edit Comments" OnClick="editComments_Click" /> 

有誰知道如何使它所以日曆當我在框中點擊時出現?我不希望能夠手動鍵入日期,但我希望能夠單擊文本框而不是按鈕。事實上,如果可能的話,我希望能夠擺脫按鈕,只需點擊框中。謝謝!

回答

0

找出來了,但我會留下問題以防其他人遇到此問題。您只需將showOn: 'button'更改爲showOn: 'focus',然後該按鈕消失,您只需單擊文本框即可查看日曆。如果您希望能夠單擊按鈕或文本框,請使用showOn: 'both'