单击日历时不显示日期选择器
本文关键字:日期 选择器 显示 日历 单击 | 更新日期: 2023-09-27 18:28:13
我有一些输入字段,它们是日期选择器,目前,当您单击字段时,工作正常。但有人问我,当用户点击日历时,日历也应该显示,但这有点让我无法工作。
我正在使用一个文本框扩展,我的代码是:
public static MvcHtmlString CalandarTextBox(this HtmlHelper htmlHelper, string prefix, string name, object value, object htmlAttributes)
{
TagBuilder tagBuilder = new TagBuilder("input");
tagBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
string template = "";
template += "<div class='"input-group input-group-IE7'">";
template += " <input class='"form-control'" type='"text'" name='"{0}'" id='"{0}'" value='"{1}'" {2}";
template += " <div class='"input-group-addon input-group-addon-IE7'"><i class='"{3}'"></i></div>";
template += "</div>";
MvcHtmlString TextBox = new MvcHtmlString(
String.Format(template, name, value, tagBuilder.ToString(TagRenderMode.Normal).Replace("<input ", " "), prefix)
);
return TextBox;
}
在我看来,这些字段的代码是:
template.Nvc.Add("[!FromDate]", Html.CalandarTextBox("glyphicon glyphicon-calendar", "FromDate", fromDateValue, new { @class = "form-control" }).ToHtmlString());
最后,我为该领域编写的Javascript是:
$("#FromDate").click(function () {
$("#Months").val(0);
});
$("#FromDate").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true
});
正如我上面所说,当我点击输入字段时,会显示日历,但如果我点击输入栏末尾的日历,则不会。
我该怎么做。
修复
$("#FromDate").datepicker({
showOn: "button",
changeMonth: true,
changeYear: true,
buttonImage: "../../images/calendar.png",
buttonImageOnly: true,
buttonText: "Select date",
dateFormat: "dd/mm/yy"
});
$("#ToDate").datepicker({
showOn: "button",
changeMonth: true,
changeYear: true,
buttonImage: "../../images/calendar.png",
buttonImageOnly: true,
buttonText: "Select date",
dateFormat: "dd/mm/yy"
});
Html
<div class="col-lg-3">
<div class="input-group">
<input type="text" class="form-control" id="datepicker">
<span class="input-group-btn">
<button type="button" class="btn btn-default" id="btnPicker">
<span class="glyphicon glyphicon-calendar"></span>
</button>
</span>
</div>
<!-- /input-group -->
</div>
Javascript
$(函数(){$("#datepicker").datepicker({changeMonth:true,changeYear:true,日期格式:"dd/mm/yy"}).datepicker("setDate",new Date());
$('#btnPicker').click(function () {
//alert('clicked');
$('#datepicker').datepicker('show');
});
});