如何循环排序有序列表项并更新类Jquery [英] How Do I Loop Through Ordered List Items And Update The Class Jquery

查看:78
本文介绍了如何循环排序有序列表项并更新类Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我创建了一个列表项id的数组,我想知道如何循环遍历数组并获取索引使用Jquery的数组,因为我只想更新数组列表中所选id的类



Hi
I have created an array of the id's of the list item and i would like to know how would i be able to loop through the array and get the index of the array using Jquery as i would like to only update the class of the selected ids which are in the array list

localStorage.selectableList = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]"




var list = JSON.parse(localStorage.selectableList);





这就是我的方式创建了我的数组



That is how i have created my array

推荐答案

你可以这样做



You can do this like

// Your array of ids
var arr = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]

// Loop through the array


.each (arr, function (i,val){
// 从数组项添加类到相应的ID
.each(arr, function (i, val) { // Add class to the respective ids from array items


' #' + val).addClass(' active');
});
('#' + val).addClass('active'); });





小提琴 [ ^ ]


这篇关于如何循环排序有序列表项并更新类Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆