0
此代码块有什么问题?它只会选择包含说明的第一个元素,但不会全选。为什么?我错过了什么?作为一个getter使用,将从第一个元素集合中总是返回时类^ ='指令'...只选择以类开头的第一个元素应全选
jQuery(document).ready(function() {
jQuery('select').select2();
// get a list of objects that begin with instructions
var classList = jQuery('a[class^="instructions"]').attr('class').split(/\s+/);
console.log(classList);
jQuery.each(classList, function (index, item) {
jQuery('.'+item+'-'+index).click(
function (event) {
event.preventDefault();
jQuery(this).parent().next().toggle();
}
);
});
});
不能保证类特定的字符串开始时的元素有多个类。 – Tushar
顺便说一句,有一个类名单已经属性 - 不需要自定义拆分。 – Sirko
最好使用数据属性来处理这类事情,其中可以控制和依赖订单。 – Utkanos