Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery Simplebar插件没有';不能使用class元素_Javascript_Jquery_Simplebar - Fatal编程技术网

Javascript jQuery Simplebar插件没有';不能使用class元素

Javascript jQuery Simplebar插件没有';不能使用class元素,javascript,jquery,simplebar,Javascript,Jquery,Simplebar,我尝试使用类元素创建滚动条,如。但实际上这个插件不起作用 HTML: 这是SimpleBar文档中的示例,您的问题涉及两个方面。文档中的这个示例有缺陷 jQuery中有两种形式的each()。有jQuery.each方法和jQuery.fn.each方法,它们是第一个方法的包装器。不同之处在于jQuery.fn方法被设计为作用于包含结果堆栈的jQuery实例(例如$(…)表达式的结果)。jQuery.each并不是为了对现有实例进行操作而编写的,而是希望同时提供要操作的元素和与需要完成的工作相

我尝试使用类元素创建滚动条,如。但实际上这个插件不起作用

HTML:

这是SimpleBar文档中的示例,您的问题涉及两个方面。文档中的这个示例有缺陷

jQuery中有两种形式的
each()
。有
jQuery.each
方法和
jQuery.fn.each
方法,它们是第一个方法的包装器。不同之处在于
jQuery.fn
方法被设计为作用于包含结果堆栈的jQuery实例(例如
$(…)
表达式的结果)。
jQuery.each
并不是为了对现有实例进行操作而编写的,而是希望同时提供要操作的元素和与需要完成的工作相关的回调

有鉴于此,他们的文档所显示的用法是错误地试图使用
jQuery.fn.each
,就好像它是
jQuery.each
表单一样

$('.simple-bar').each((index, element) => new SimpleBar(element));`

此表单正确地使用了
jQuery.fn.each
版本,只给它一个回调,该回调将用于对jQuery实例中的结果堆栈执行操作。

我不确定为什么这些文档将
each(element,new SimpleBar())
显示为有效模式。至少在api中,没有定义每个参数都有两个参数。@Taplar:
$('.simple bar')。每个(element=>new SimpleBar(element))
都不起作用。垃圾,因为索引太笨了<代码>$('.simple bar')。每个((索引,元素)=>新的SimpleBar(元素))也与我的“它不在api中”相关,
$('.simple bar')。每个((索引,元素)=>新SimpleBar(元素))您的代码现在可以工作了。请补充答案。
$('.simple-bar').each(element, new SimpleBar());
$('.myElements').each(element, new SimpleBar());
$('.simple-bar').each((index, element) => new SimpleBar(element));`