我正在尝试运行以下脚本以在 magento 2 中添加展开/折叠但是当在前端单击事件时会生成错误。
Uncaught ReferenceError: $header is not defined
我使用的代码是
define([
"jquery"
], function($){
"use strict";
return function sidebar(config, element) {
$(".filter-ab").click(function () {
$header = $(this);
//getting the next element
$content = $header.next();
//open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
$content.slideToggle(500, function () {
//execute this after slideToggle is done
//change text of header based on visibility of content div
$header.text(function () {
//change text based on condition
return $content.is(":visible") ? "Collapse" : "Expand";
});
});
});
}
});
答案 0 :(得分:0)
我认为你需要使用 var header 而不是 $header