2016-07-15 68 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'