我有输入字段是日期选择器,目前,单击字段时工作正常。但有人问我,当用户点击日历时,日历也会显示,但这是我无法工作的。
我使用的是文本框扩展名,我的代码是:
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
});
正如我上面所说,当我点击输入字段时显示日历,但是如果我点击输入字段末尾的日历则不显示。
我该怎么做。
答案 0 :(得分:0)
修复
$("#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
$(function(){ $(&#34;#日期选择器&#34)。日期选择器({ changeMonth:是的, changeYear:true, dateFormat:&#34; dd / mm / yy&#34; })。datepicker(&#34; setDate&#34;,new Date());
$('#btnPicker').click(function () {
//alert('clicked');
$('#datepicker').datepicker('show');
});
});