Display different background pictures according to the data returned by the ajax query

to do a special effect, display different background pictures in div according to the returned json data, one background picture for one data, and one cycle for 4 records. What to do, the finished effect

clipboard.png

Jul.23,2021

my idea is to process the data first, in groups of four, and then push into a large array, the background color (if fixed, it can be written directly in a new array and then bound to the data), then traverse the large array, and then traverse each subarray of the large array (where the background color and data binding are performed), and then dynamically create the div, To render


//html------
<div>
    <ul id="rs">    
    </ul>
</div>

//script------
var arrbg = ["red","green","yellow","blue"]
var arr = [{title:'1'},{title:'2'},{title:'1'},{title:'1'},{title:'1'},{title:'1'},{title:'1'},{title:'1'},{title:'1'}]
        var num = 0;
        arr.map(function(item,index){
            if(num == 4){
                num = 0
            }
            var oui = document.getElementById("rs")
            oui.innerHTML += "<li>"+index+"</li>";
            oui.getElementsByTagName("li")[index].style.background=arrbg[num];
            numPP;
        })


css:

.class1{
    background:;
}
.class2{
    background:;
}
.class3{
    background:;
}
.class4{
    background:;
}
js:
jsondata/**/
var odiv = '',bg='';
for(var item in jsondata ){
    var bgindex = item%4
     switch (bgindex ){
        case 0:
            bg = 'class1'
            break;
        case 1:
            bg = 'class2'
            break;
        case 2:
            bg = 'class3'
            break;
        case 3:
            bg = 'class4'
            break;
        default:
            break;
            }
    odiv = '<div class="'+ bg +'">jsondata[item].data</div>'
    $('-sharpparentElement').append(odiv)
}









the problem has been solved. It's a little late to see the reply, but thank you for your help

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ec85bb-2ec6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ec85bb-2ec6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?