简体   繁体   English

jquery datepicker无法点击按钮

[英]jquery datepicker not working clicking on a button

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 我正在研究jquery datepicker。它正在点击一个按钮,但只在mozilla firefox中,但不在谷歌浏览器中也不在IE中。请告诉我该做什么,以便datepicker适用于所有浏览器。请使用jsfiddle

HTML HTML

<input type="button" id="selectdate" value=""> 


<textarea name="dates" id="dates" maxlength="160" placeholder="your message" rows="4" cols="50"></textarea> 

JQUERY JQUERY

$( "#selectdate" ).datepicker({ 
altField: $('#dates').val(), 
numberOfMonths:1, 
altFormat: "yy-mm-dd", 
minDate: -0, 
onSelect: function( selectedDate ) { 
$("#selectdate").val(''); 

$('#dates').val($('#dates').val()+','+selectedDate); 
} 
}); 

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 无法重新创建问题...但我认为您需要的是使用showOnbuttonImage选项而不是使用按钮来呈现日期选择器

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 演示: 小提琴

Try following.. 试试以下..

Demo Fiddle 演示小提琴

JS: 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);
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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