0
我有日期選擇器的輸入字段,目前在您點擊字段時工作正常。但有人問我,日曆應該也會顯示,當用戶點擊日曆,但這是我無法工作的位。點擊日曆時不顯示日期選擇器
我使用的是文本框的延伸和我的代碼是:
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
});
正如我所說的,顯示日曆時,當我點擊輸入字段,但不是如果我點擊t他在輸入字段的末尾記錄日曆。
我該怎麼做。
從我的頭頂開始:您將日曆綁定到輸入框。使用開發工具嘗試查看「calendar」thingy是否有可用來綁定點擊的類。 – Sphaso 2014-10-29 14:42:05
只需向我們展示您嘗試定位的數據添加器輸入的渲染內容。 – 2014-10-29 20:49:56