【发布时间】:2018-12-04 04:41:47
【问题描述】:
我有一个<div>,在data-options 属性中有一些选项:
<div class="slider" data-options="container: value, speed: 1000, edgePadding: 45, lazyload: true">
此属性包含我需要的每个 <div> 和 .slider 类的参数。
我将这些参数保存到 options 变量中:
var options = value.dataset.options;
然后我需要为每个 .slider 元素将这些选项传递给函数 tns:
var forEach = function (array, callback, scope) {
for (var i = 0; i < array.length; i++) {
callback.call(scope, i, array[i]);
}
};
var sliders = document.querySelectorAll('.slider');
forEach(sliders, function (index, value) {
var options = value.dataset.options;
let slider = tns({
/************ PARAMETERS GO HERE ***********/
});
});
我怎样才能做到这一点?
【问题讨论】:
标签: javascript html attributes custom-data-attribute