jQuery错误:无法使用'在'操作员搜索'使用'在100
jQuery error: Cannot use 'in' operator to search for 'using' in 100
这段代码曾经工作过,但现在抛出了这个错误,我真的不确定它意味着什么。我在谷歌上搜索了一下,但我发现的似乎很接近,但并不完全符合我的问题。
错误:未捕获的类型错误:无法使用"in"运算符在100 中搜索"using"
JS代码:
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset(100).top
}, 1500, 'easeInOutExpo');
//check to see if its a drop down button
if(!$(this).hasClass("dropdown"))
{
if ( $(window).width() < 767){
$('.navbar-toggle').click();
}
}
event.preventDefault();
});
这似乎是造成问题的部分:
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset(100).top
}, 1500, 'easeInOutExpo');
检查您的$($anchor.attr('href')).offset(100).top
值,或者只使用静态数字代替它,如果它正常,那么该值一定有一些错误。
我知道这个问题很古老,但我刚刚遇到了一个类似的问题。如果你查看.offset(coordinates)
上的jQuery文档,你会发现它不是在寻找实际的坐标,而是一个包含坐标的对象:
坐标
类型:PlainObject
一个包含属性
top
和left
的对象,这两个属性是指示元素的新顶部和左侧坐标的数字。
所以,如果你这样做:
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
var myOffset = { top: "100px", left: "0px" };
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset(myOffset).top
}, 1500, 'easeInOutExpo');
//check to see if its a drop down button
if(!$(this).hasClass("dropdown"))
{
if ( $(window).width() < 767){
$('.navbar-toggle').click();
}
}
event.preventDefault();
});
(注意myOffset
变量及其在.offset()
调用中的使用)
你应该得到想要的结果!
相关文章:
- 用程序搜索JQuery数据表中的文本
- 在html Select中添加搜索
- Ajax Live搜索发布到Laravel视图
- 谷歌放置API:按国家或餐馆名称搜索餐馆
- 学生搜索项目jquery/javascript
- 用于搜索的聚合物嵌套绑定
- 在javascript中搜索具有重复值的两个数组中的匹配值
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- 使用javascript搜索具有用户输入的数组
- 不断获得"未捕获的类型错误:无法使用'在'操作员搜索'191'"jQu
- TypeError:无法使用'在'操作员搜索'SUPPORT_WL_SERVER_CHANGE&
- TypeScript错误无法使用'在'操作员搜索'_id'用于typescript和pou
- 未捕获的类型错误:无法使用'在'操作员搜索'7'当我试着比较日期的时候
- jQuery错误:无法使用'在'操作员搜索'使用'在100
- 未捕获的类型错误:无法使用'在'操作员搜索'长度'在里面
- 无法使用'在'操作员搜索'728'在里面
- 未捕获的类型错误:无法使用'在'操作员搜索'123'中
- "未捕获的类型错误:无法使用'在'操作员搜索'长度'在“;由Datatable
- 无法使用'在'操作员搜索'18'在canjs中
- 未捕获的类型错误:无法使用'在'操作员搜索'长度'在里面