简体   繁体   中英

How to set the jquery datepicker value to null?

I need to set the initial value to null on my datepicker. So when the page loads , there is nothing in the text box. I don't mind if when the datepicker is opened, today date is highlighted as long as the value is not selected unless the user has chosen one.

I tried a placeholder, but it only appears after I delete todays date... (it would be great to have a placeholder aswell)

Help please ! ASP.Net MVC 4 application using razor2 views.

  <div class="controls">
     @Html.TextBoxFor(model => model.Appointment, 
     new {@id = "AcceptedDatepicker",@class = "span12 m-wrap"})
  </div>

      $("#AcceptedDatepicker").datepicker({
        dateFormat: 'D dd M yy',
        minDate: 0,
        highlightWeek: true,
        showAnim: "scale",
        showOptions: {
            origin: ["top", "left"]
        }
    });

Try this,

$("#AcceptedDatepicker").datepicker({
        dateFormat: 'D dd M yy',
        minDate: 0,
        highlightWeek: true,
        showAnim: "scale",
        showOptions: {
            origin: ["top", "left"]
        }
    }).val('');

or this,

@Html.TextBoxFor(model => model.Appointment, string.Empty, new {@id = "AcceptedDatepicker",@class = "span12 m-wrap"})

I applied all solutions given above but did not worked yet . On razor my code is as following...i want that textbox as null while its showing current date as default date.

<div class="col-md-8 input-group" data-date-format="dd/mm/yyyy">
@Html.TextBoxFor(model => model.StrJoiningDate, new { @class =     
"DatepickerNew ", id = "txtJoiningDate",})

And on javascript/jquery i added following code

<script type="text/javascript">
     $(function () {

        $('.DatepickerNew').daterangepicker({
            singleDatePicker: true,
            showDropdowns: true,
            locale: {
            format: 'DD/MM/YYYY'
        },
        minDate: (Date, "01/01/1920"),
        maxDate: (Date, "01/01/2099")

    });
});
</script>

css for it as

http://cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css

Looking for help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM