items
まず、次のように変更するとよいでしょう。
var items = [
[
'font-weight: bold',
'text-decoration: underline',
'text-transform: uppercase',
],
[
'color: purple',
'color: yellow',
],
[
'color: pink'
]
];
$(document).ready(function() {
$('li').each(function(liIndex, li) {
$('span', this).each(function(index, el) {
var curCSS = items[liIndex][index].split(':');
$(this).css(curCSS[0], curCSS[1])
});
});
});
デモ1
items
構造を変更したくない場合は、次のことを試してください。
var items = [
{
spanOne: 'font-weight: bold',
spanTwo: 'text-decoration: underline',
spanThree: 'text-transform: uppercase'},
{
spanOne: 'color: purple',
spanTwo: 'color: yellow'},
{
spanOne: 'color: pink'}
];
$(document).ready(function() {
var ref = ['spanOne', 'spanTwo', 'spanThree']; // an array to make reference
$('li').each(function(liIndex, li) {
$('span', this).each(function(index, span) {
var curCSS = items[liIndex][ref[index]].split(':');
$(this).css(curCSS[0], curCSS[1])
});
});
});
デモ2