0

テキストボックスに ajax カレンダーを適用し、その選択に次のチェックを適用しました

 function checkDate(sender, args) {
        if (sender._selectedDate > new Date()) {
            alert("You cannot select a day future than today!");
            sender._selectedDate = new Date();
            // set the date back to the current date
            sender._textbox.set_Value(sender._selectedDate.format(sender._format))
        }
    }

私のhtmlコードは次のとおりです。

 <asp:TextBox ID="txtDOB" Width="140px" MaxLength="50" runat="server"></asp:TextBox>
                            <ajaxctrl:calendarextender onclientdateselectionchanged="checkDate" id="cale_txtDOB"
                                runat="server" targetcontrolid="txtDOB" format="MM/dd/yyyy" cssclass="cal_Theme1">
                            </ajaxctrl:calendarextender>

正常に機能していますが、日付を手動で入力すると機能しません。どうすれば両方の方法を機能させることができますか。

ユーザーが手動で入力すると日付もチェックされ、ユーザーがカレンダーから選択すると日付も検証されます。

4

2 に答える 2

1

これは、変更された JavaScript 関数です。

    function checkDate(sender, args) {
        //alert(sender._selectedDate > new Date());
        if (sender._selectedDate > new Date()) {
            alert("You cannot select a day future than today!");
            sender._selectedDate = new Date();
            // set the date back to the current date
            sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            return false;
        }
    }

これは新しい JavaScript 関数です。関数の下に追加するだけです。

    function checkDate1(txt) {
        if (new Date(txt.value) > new Date()) {
            alert("You cannot select a day future than today!");
            return false;
        }
    }

ページの Page_Load イベントに移動し、次のコード行を追加します。

    this.txt.Attributes.Add("onblur", "checkDate1(this);");

これらの関数名は、少し急いで書いたので、変更してもかまいません。それをうまくテストする時間もあまりありませんでした。ご不明な点がございましたら、お知らせください。

于 2012-11-20T15:13:39.687 に答える
0

jQuery Changeメソッドを試しましたか?

$('#textBoxName').change( function() {
  if ($(this).val() > new Date()) {
     alert("You cannot select a day future than today!");
       var today=new Date();
       $('#textBoxName').val(today);
  }
});
于 2012-11-20T15:30:56.663 に答える