[英]How to solve type error length is not defined
I use jquery 3.0.1. 我使用的是jQuery 3.0.1。 When my code is executed, I receive the error:
执行我的代码后,我收到错误消息:
TypeError: $(...).length is not a function
TypeError:$(...)。length不是一个函数
How can I solve it? 我该如何解决?
Code: 码:
$(document).ready(function () {
size_li = $("#myList li").length();
x=3;
$('#myList li:lt('+x+')').show();
$('#loadMore').click(function () {
x= (x+5 <= size_li) ? x+5 : size_li;
$('#myList li:lt('+x+')').show();
});
$('#showLess').click(function () {
x=(x-5<0) ? 3 : x-5;
$('#myList li').not(':lt('+x+')').hide();
});
});
it is .length
not .length()
that is the reason of the error change the line 错误的原因是
.length
而不是.length()
改变了行
size_li = $("#myList li").length();
to 至
size_li = $("#myList li").length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.