|
发表于 2024-1-7 14:45:44
|
显示全部楼层
IP:亚太地区
请老师帮忙,我这个按你的代码制作的,为什么看不到图片?
- <style>
- #calendar td {text-align:center;font-size:1.2em;font-weight:bold;color:white;}
- #calendar table {width:100%;}
- #calendar th {color:skyblue;font:bold 1.5em '\5fae\8f6f\96c5\9ed1';}
- #calendar {width:90%;padding:8px;margin:auto;}
- #outBlk {width:640px;height:850px; margin:auto;overflow:hidden;position:relative;padding:16px 12px;text-align:center;border-radius:32px;
- background:darkgray url([url]https://s3.bmp.ovh/imgs/2024/01/05/b1e4df02fb672475.jpg[/url]) no-repeat center/cover;box-shadow:2px 2px 8px black;}
- #selMonth {padding:10px;margin:2px;}
- #selMonth, #prem, #nextm {border:none;background-color:lightgray;}
- #inBlk {width:320px;position:absolute;right:10px;bottom:10px;font-size:13px;}
- </style>
- <div id="outBlk">
- <div id='inBlk'>
- <input type='button' id='prem'value='◄' title='上一个月'/>
- <input id="selMonth" type="month" min="2024-01" max="2024-12" />
- <input type='button' id='nextm' value='►' title='下一个月' />
- <div id='calendar'></div>
- </div>
- </div>
- <script>
- var bkpics = [
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/222340yv1pvkpta60k41kk.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/222415lb5ex8o9yxrohxel.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/222416cy0mkyu8mdkp58m9.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/222648n2q72y77mrc700hs.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/222648x8k4wmthhcr9o9wh.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/222649kogzouzup7gvq5no.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/223409cslehe8erle0lxgo.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/223450azfozpnwefcmjop2.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/223607zbhplp6d23hy8thy.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/223543tln1zu1hj83z1bmj.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/224145eqk2arczcf24rmat.jpg",
- "http://www.yinhuabbs.cn/data/attachment/forum/202201/22/223509f7i7v7nqmvpvekpi.jpg"
- ];
- var chkMonth = new Date();
- var cur_month = chkMonth.getMonth()+1;
- selMonth.defaultValue = `${chkMonth.getFullYear()}-${cur_month < 10 ? '0'+cur_month :''+cur_month}`;
- prem.onclick = function() {
- selMonth.stepDown(1);
- showTable();
- }
- nextm.onclick = function() {
- selMonth.stepUp(1);
- showTable();
- }
- selMonth.oninput = function(e) {
- if('' === e.target.value) selMonth.value = '1970-01';
- else return false;
- }
- function mkTab(yv, mv) { // 构造月历表格
- let tmp_d = new Date(yv, mv-1, 1);
- let first_d = tmp_d.getDay(); // 这个月的第一天是星期几
- tmp_d = new Date(yv, mv, 0);
- let last_d = tmp_d.getDate() // 这个月有多少天
-
- // 表头是不变的
- let tabStr = "<table><tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>";
- // 第一行需特殊处理
- tabStr += '<tr>';
- let dv = 1, offIdx = 7 - first_d;
- for(i = 0; i < first_d; i++) tabStr += '<td> </td>'; // 第一行加上适当的空格
- for(i = 0; i < offIdx; i++,dv++) tabStr += `<td>${dv}</td>`; //
- tabStr += '</tr><tr>';
- // 其余的行处理
- for(i = dv; i <= last_d; i++) {
- tabStr += `<td>${i}</td>`;
- if((i-offIdx) % 7 == 0) tabStr += '</tr><tr>'; // 七个日子就换一行
- }
- tabStr += "</tr></table>"
- calendar.innerHTML = tabStr;
- }
- function showTable() {
- let ym = selMonth.value.split('-');
- mkTab(parseInt(ym[0]),parseInt(ym[1]));
- outBlk.style.backgroundImage = `url(${bkpics[parseInt(ym[1]) - 1]})`;
- }
- selMonth.onchange = showTable;
- showTable();
- </script>
- <br /><br /><br><br>
- <video src="https://music.163.com/song/media/outer/url?id=1854387200.mp3" width="1" height="1" controls="" autoplay=""></td></tr>
复制代码
|
|