1
我有一個問題,當我使用datepicker自定義所需的字段。 如果我點擊下一個按鈕,字段自定義決定日期顯示「該字段必須是有效的日期」。 如果我改變datepicker的格式日期是這樣的:「dateFormat:'d/m/yy'」它是工作,但我想只顯示月份和年份而不是日期。 感謝您的幫助。Jquery-ui datepicker自定義顯示「該字段必須是有效日期」
我的看法是:
<script>
$(document).ready(function() {
$(".DatepickerMonthYears").datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'm/yy',
required: false,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
$(".DatepickerMonthYears").focus(function() {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
});
</script>
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { id = "FormAction" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Create </legend>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Step1</a></li>
</ul>
<div id="tabs-1">
@Html.Partial("Step1", Model)
</div>
<div class="buttonNextPrevious">
<a id="previous" class="linkLikeButton" href="#">Previous Step</a>
<a id="next" class="linkLikeButton" href="#">Next Step</a>
</div>
</div>
</fieldset>
}
我的部分觀點是:
@model SiteWebEmpty.Models.ArticleRequest.CreateArticle.DisplayCreateAllStep
<fieldset>
<legend>Step 1</legend>
@Html.LabelFor(model => model.Step1.CustomerDecisionDate, new { @class = "LabelStep1" })
@Html.TextBoxFor(step1 => step1.Step1.CustomerDecisionDate, new { @class = "DatepickerMonthYears" })
@Html.ValidationMessageFor(model => model.Step1.CustomerDecisionDate)
<br />
</fieldset>
我的模式是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using SiteWebEmpty.Models.AttributValidation;
namespace SiteWebEmpty.Models.Step1
{
public class Step1
{
[Display(Name = "Customer Decision Date")]
public DateTime CustomerDecisionDate { get; set; }
}
}
UPDATE
此鏈路上的溶液: jQuery UI DatePicker to show month year only 以「埃裏克波爾德」的工作後,但如果我的「MM-/ YY改變格式日期「YY-MM」)1具有相同的錯誤:/
UPDATE2 我找到了解決辦法,我添加了一個腳本,它的工作原理 腳本:jquery.ui.datepicker-fr.js
可能DUP:HTTP://計算器.COM /問題/ 2208480/jQuery的日期選擇到節目 - 月 - 年,只有 – Rafay 2012-03-28 17:48:01
我在這篇文章中的代碼有同樣的問題,但謝謝你的幫助:)。我更新了我的文章:) – Zoners 2012-03-28 19:24:48
我找到了解決方案:)我更新了我的文章:)。 – Zoners 2012-03-29 08:21:45