Object [object Object] has no method when using bootstrap Datepicker

寵の児 提交于 2019-12-23 04:42:17

问题


I am using this DatePicker and I get the following Error when trying to use it:

TypeError: Object [object Object] has no method 'datetimepicker'

It gives the error on my script section which looks like this:

 $(function () {
        $('#StartDate').datetimepicker({
            pickTime: false
        });
    });

And here is my HTML:

<div id="StartDate" class="input-append">
                        <input data-format="yyyy-MM-dd" type="text" />
                        <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                    </div>

I have imported all the required libraries and my base Jquery library is 1.9.0

Any Ideas?


回答1:


I also had this issue, i solved it by using the following HTML for my date picker.

<div id="StartDate" class="input-append date">
    <input type="text" />
    <span class="add-on">
    <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
    </span>
</div>

This is the following libraries that needs to be referenced.

 <script type="text/javascript"
 src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script> 
<script type="text/javascript"
 src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js">
</script>
<script type="text/javascript"
 src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js">
</script>

to bind the datepicker the following can be used.

$(function () {
  $('#StartDate').datetimepicker({
     pickTime: false
   })
   .on('changeDate', function (ev) {
    TaskSubmitViewModel.TaskStartDate(ko.toJSON(ev.date).substr(1, 10))

      });
});



回答2:


I had this similar problem, getting "[Object Object]", so I hope this helps you... Have you tried changing $('#StartDate').datetimepicker({ to $('#StartDate').datetimepicker.val()({? If I'm right in thinking, your selecting the datepicker element, and not it's value.



来源:https://stackoverflow.com/questions/14782728/object-object-object-has-no-method-when-using-bootstrap-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!