问题
I am working on jquery datepicker.It is working on clicking on a button but only in mozilla firefox but not in google chrome not in IE too.Please tell me what to do so that the datepicker will work in all browsers.Please the jsfiddle
HTML
<input type="button" id="selectdate" value="">
<textarea name="dates" id="dates" maxlength="160" placeholder="your message" rows="4" cols="50"></textarea>
JQUERY
$( "#selectdate" ).datepicker({
altField: $('#dates').val(),
numberOfMonths:1,
altFormat: "yy-mm-dd",
minDate: -0,
onSelect: function( selectedDate ) {
$("#selectdate").val('');
$('#dates').val($('#dates').val()+','+selectedDate);
}
});
回答1:
Try following..
Demo Fiddle
JS:
$("#selectdate").datepicker({
altField: $('#dates').val(),
numberOfMonths: 1,
altFormat: "yy-mm-dd",
minDate: -0,
buttonImage: 'http://placehold.it/32',
showOn: "both",
onSelect: function (selectedDate) {
$("#selectdate").val('');
var attr = $("#dates").attr("selectedDate");
if (typeof (attr) !== 'undefined' && attr !== '') {
if ($('#dates').val() !== '') {
var tmpVal = $('#dates').val().substring(0,$('#dates').val().indexOf(attr));
console.log(tmpVal);
$('#dates').val(tmpVal + selectedDate);
$('#dates').attr("selectedDate", selectedDate);
} else {
$('#dates').val(selectedDate);
}
} else {
$('#dates').attr("selectedDate", selectedDate);
$('#dates').val($('#dates').val() + selectedDate);
}
}
});
回答2:
Not able to recreate the problem... but I think what you need is to use the showOn and buttonImage options instead of using a button to render the datepicker
like
<input type="text" id="selectdate" value="" style="display: none">
then
$("#selectdate").datepicker({
altField: $('#dates').val(),
numberOfMonths: 1,
altFormat: "yy-mm-dd",
minDate: -0,
buttonImage:'http://placehold.it/32',
showOn: "both",
onSelect: function (selectedDate) {
$("#selectdate").val('');
$('#dates').val($('#dates').val() + ',' + selectedDate);
}
});
Demo: Fiddle
来源:https://stackoverflow.com/questions/19580797/jquery-datepicker-not-working-clicking-on-a-button