问题
I'm using the jQuery-UI datepicker in this way:
var datepickerOpts = {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
showWeek: true,
onClose: function(dateText, inst) {
if (($("#BeginTime").val()).length == 0) {
$("#BeginTime").timeEntry("setTime", new Date(0, 0, 0, 0, 0, 0));
}
$("#BeginTime").focus();
}
}
$("#BeginDate").datepicker(datepickerOpts);
The related [cs]html is:
<tr id="trBeginDate">
<td>
</td>
<td>
@Html.LabelFor(m => m.BeginDate)
</td>
<td style="padding-right: 20px;">
@Html.TextBoxFor(m => m.BeginDate, new {alt = "date-us", style = "width: 109px;"})
</td>
<td>
@Html.LabelFor(m => m.BeginTime)
</td>
<td style="padding-right: 20px;">
@Html.TextBoxFor(m => m.BeginTime, new {style = "width: 109px;"})
</td>
</tr>
What I want to show as a default value in the BeginTime textbox is "00:00:00", not just "00:00" as I get:

Actually, "00:00" is probably okay for the default begin time of midnight, but I need the default end time to be "23:59:59" not what it is now ("23:59") because that way practically an entire minute is potentially lost (from "23:59:01" to "23:59:59"). And so, "00:00" should be "00:00:00" to have a consistent format with "23:59:59").
Anyway, I tried this, but it doesn't work at all (nothing is added to the BeginTime textbox):
. . .
onClose: function(dateText, inst) {
if (($("#BeginTime").val()).length == 0) {
$("#BeginTime").text("00:00:00");
. . .
nor did this:
. . .
onClose: function(dateText, inst) {
if (($("#BeginTime").val()).length == 0) {
$("#BeginTime").text.val("00:00:00");
. . .
So how can I set the BeginTime value to "00:00:00"?
回答1:
Take a look at the $.timeEntry() documentation, under the 'formats' tab is how to set different default formats. Based on your other question here is how you would set seconds and a 24 hour clock:
// Start Date / Time
var beginDatepickerOpts = {
...
}
$('#BeginTime').timeEntry({
showSeconds: true,
show24Hours: true
});
$("#BeginDate").datepicker(beginDatepickerOpts);
// End Date / Time
var endDatepickerOpts = {
...
}
$('#EndTime').timeEntry({
showSeconds: true,
show24Hours: true
});
$("#EndDate").datepicker(endDatepickerOpts);
EXAMPLE
JSFiddle Example here.
回答2:
Just go to the link and you will get the required stuff. http://www.avisbra.it/wp-content/plugins/lbwp_book/js/jquery/plugin/timepicker/
来源:https://stackoverflow.com/questions/16989566/how-can-i-add-seconds-to-my-timepicker