一、主要函数 /* * 生成十二个月的日历 * year:年份 * dataObj:传入的时间数据,年月日 * data:需要标注的日期,日期需要正序排列 * separator:时间的分隔符 * div:父组件div组件 */ function generateCalendar(obj){ let year = obj.year; let dataObj = obj.dataObj; let data = dataObj.data; let type = dataObj.type; let attribute = dataObj.attribute; let separator = dataObj.separator; let div = obj.div; //得到十二个月份 let month = []; for(let i = 1;i < 13;i++){ month.push(i); } div.style.width = "100%"; let table = null; let thead = null; let tr = null; let td = null; //遍历每一月 for (let i = 0;i < month.length;i++){ table = document.createElement("table"); table.cellPadding = "5px"; table.style.margin = "10px"; table.style.float = "left"; //获取该月的天数 let day = monthDay(year,i+1); //添加标题XXXX年XX月 td = document.createElement("td"); td.innerText = year+"年"+(i+1)+"月"; td.colSpan = "7"; td.style.textAlign = "center"; td.style.border = "1px solid"; tr = document.createElement("tr"); tr.appendChild(td); thead = document.createElement("thead"