MVC: How do you remove focus from a datepicker?
I have this Editor Template so that I have a datepicker set for date input. See
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" 开发者_如何学C%>
<%:Html.TextBox("", (Model.HasValue ? Model.Value.ToLongDateString() : string.Empty),
new { @class = "datePicker" })%>
When I load a page with a date input field I automatically get the datepicker invoked. I would rather wait until the user clicks on the field or button.
I am thinking that I want to use a JQuery Blur command associated with this Editor Template to stop this happening. But is that the right way, can it be done like that, or is there a better way?
If you don't want the calendar to appear until something is clicked, then you can try the showOn option, possibly like:
$(document).ready(function () {
$(".datepicker").datepicker({
showOn: "button",
buttonImage: "/images/calendar.gif",
buttonImageOnly: true,
buttonText: 'Calendar'
});
})
精彩评论