Javascript g.size() 不是函数 - Jquery 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38617023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:39:39  来源:igfitidea点击:

g.size() is not a function - Jquery Error

javascriptjquerymomentjsbootstrap-datetimepicker

提问by Sajak Upadhyaya

I have been trying to use bootstrap datetimepicker and have all the components on my scripts like Moment JS, bootstrap-date-time js, and bootstrap js but I am getting g.size() is not a function error. I am trying to run the following function

我一直在尝试使用 bootstrap datetimepicker 并在我的脚本中拥有所有组件,如 Moment JS、bootstrap-date-time js 和 bootstrap js,但我得到 g.size() 不是函数错误。我正在尝试运行以下功能

$(function(){
    $('#datetimepicker').datetimepicker();
  });

采纳答案by kris

I had the same error as you, and I could not find a solution for it anywhere. In fact the only reference to the g.size() is not a functionerror was this question, at the time with only a single down vote.

我和你有同样的错误,我在任何地方都找不到解决方案。事实上,唯一提到g.size() is not a function错误的是这个问题,当时只有一个反对票。

My solution was to find a different datetime picker that actually worked

我的解决方案是找到一个实际工作的不同日期时间选择器

I found this one: https://github.com/xdan/datetimepicker, it was quite easy to get working:

我找到了这个:https://github.com/xdan/datetimepicker,工作起来很容易:

  1. download the zip from github
  2. Include the files :

    <link href="./js/datetimepicker-master/build/jquery.datetimepicker.min.css" rel="stylesheet"> <script src="./js/datetimepicker-master/build/jquery.datetimepicker.full.min.js"></script>

  3. This HTML

    <input id="datetimepicker" type="text" />

  4. And this JS

    $.datetimepicker.setLocale('en');
    $('#datetimepicker').datetimepicker();

  1. 从github下载zip
  2. 包括文件:

    <link href="./js/datetimepicker-master/build/jquery.datetimepicker.min.css" rel="stylesheet"> <script src="./js/datetimepicker-master/build/jquery.datetimepicker.full. min.js"></script>

  3. 这个 HTML

    <input id="datetimepicker" type="text" />

  4. 而这个JS

    $.datetimepicker.setLocale('en');
    $('#datetimepicker').datetimepicker();

I got this up and working in a tiny fraction of the amount of time I'd wasted trying to get the bootstrap datetimepicker to stop giving me the g.size()error.

我得到了这个并在我浪费的时间的一小部分时间内工作,试图让引导程序 datetimepicker 停止给我g.size()错误。

Of course there are many other datetime pickers available:

当然,还有许多其他日期时间选择器可用:

See this post for many more options : whats-a-good-javascript-time-picker

有关更多选项,请参阅此帖子:whats-a-good-javascript-time-picker

回答by Agu Dondo

.size()was removed in version 3 of jQuery, use .lengthinstead.

.size()已在 jQuery 版本 3 中删除,请.length改用。

In your example, replace g.size()for g.length.

在您的示例中,替换g.size()g.length.

回答by Al Grant

The g.size error is known by the developers and exists with newer versions of jquery.

g.size 错误是开发人员已知的,并且存在于较新版本的 jquery 中。

If you wish to use that datetimepicker then go back to jquery 2.1.4 or earlier.

如果您希望使用该日期时间选择器,请返回 jquery 2.1.4 或更早版本。

The bug is listed here :

该错误在此处列出:

https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1714

回答by Tapash

Please use latest bootstrap-datetimepickerto get rid of this issue. I have used below version and the error is gone.

请使用最新的bootstrap-datetimepicker来解决这个问题。我使用了以下版本,错误消失了。

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

jQuery v3.3.1is used.

使用 jQuery v3.3.1

回答by Tom

Check your version of jQuery. I was using the latest(3.1.1) some plugins i use were throwing this error.

检查您的 jQuery 版本。我正在使用最新的(3.1.1)一些我使用的插件抛出这个错误。

according to the docs: The .size() method is deprecated as of jQuery 1.8. Use the .length property instead.

根据文档: .size() 方法从 jQuery 1.8 开始被弃用。请改用 .length 属性。

( it was removed in 3.0 )

(它在 3.0 中被移除)

so a simple rollback to a version before 3.0 did the trick.

所以简单地回滚到 3.0 之前的版本就可以了。

edit: whoops, as A. Wolff says in the comments.

编辑:哎呀,正如 A. Wolff 在评论中所说的那样。

edit 2: another thing... if you want to keep your jquery version up to date, you could include the jquery-migrate plugin to your project - https://github.com/jquery/jquery-migrate

编辑 2:另一件事......如果你想让你的 jquery 版本保持最新,你可以将 jquery-migrate 插件包含到你的项目中 - https://github.com/jquery/jquery-migrate