// 优化后的banner.js
(function () {
    // 设置innerHTML
    function setInnerHTML(el, html) {
        if (el) el.innerHTML = html;
    }
    // AJAX GET请求
    function ajaxGet(url, callback, errorCallback) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    try {
                        var res = JSON.parse(xhr.responseText);
                        callback(res);
                    } catch (e) {
                        console.error('JSON解析失败', e);
                        if (errorCallback) errorCallback(e);
                    }
                } else {
                    console.error('请求失败', xhr.status);
                    if (errorCallback) errorCallback(xhr.status);
                }
            }
        };
        xhr.send();
    }
    // 渲染banner
    function renderBanner(bannerList) {
        var bannerHtml = '';
        bannerList.forEach(function (banner) {
            bannerHtml += '
' +
                '
' +
                '
' +
                '

' +
                '
' +
                '
' +
                '
' + (banner.title || '') + '' +
                '
' + (banner.desc || '') + '' +
                '
' +
                '查看详情' +
                '' +
                '
' +
                '
' +
                '