javascript動態創建div循環列表


動態循環加載列表,實現vue中v-for的效果

效果圖:

代碼:

var noApplicationRecord = document.getElementById('noApplicationRecord')

//模擬數據
var data = [
    { business: '萬達影院(萬勝廣場店)', count: '325', num: '20170012565863565656', time: '2017-10-12 16:30', license: '粵A88888' },
    { business: '麥當勞', count: '111', num: '20170012565863565656', time: '2017-10-12 16:30', license: '粵A99999' },
    { business: '肯德基', count: '456', num: '20170012565863565656', time: '2017-10-12 16:30', license: '粵A45466' }
]
//繪制單個div
function setDiv(item){
    var div = '<div class="body-no-list"><div class="body-no-list-header" ><div class="body-no-list-header-title">'
        + item.business
        + '</div><div class="body-no-list-header-txt">消費金額:&nbsp;'
        + item.count
        + '元<br>消費單號:&nbsp;'
        + item.num
        + '<br>提交時間:&nbsp;'
        + item.time
        + '</div></div><div class="body-no-list-bottom"><div class="body-no-list-bottom-vehicl">'
        + item.license
        + '</div><div><button>撤銷</button><button> 修改</button></div></div></div> '
    return div
}
//循環加載到頁面
function getnoApplicationData(){
    var html = ''
    for(var i = 0;i<data.length;i++){
        html += setDiv(data[i])
    }
    noApplicationRecord.innerHTML = html
}

 window.onload = getnoApplicationData()
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM