1 Star 0 Fork 0

mengmenghao / 我的个人网站

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
shiyan7.html 3.91 KB
一键复制 编辑 原始数据 按行查看 历史
mengmenghao 提交于 2020-04-24 22:37 . 第五次
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
/* 179000522廖孟豪 */
//1、
// console.log(x); //结果:undefined
// //var x;变量声明提升,但是并没赋值,所以是undefined;
// var x = 1;
// console.log(y); //结果:undefinedUncaught ReferenceError: y is not defined
// let y = 2;
//let不会变量声明提升
//2、
// for (let num = 1; num < 10; num++) {
// console.log(num); //循环打印出1-9
// }
// console.log(num); //报错,用let定义的num无法进行外部访问
//3、
// let a1, b1, c1 = [1, 2, 3, ];
// console.log(a1, b1, c1); //undefined undefined (3) [1, 2, 3]
// let [a2, b2, c2] = [1, 2, 3, ];
// console.log(a2, b2, c2); //1 2 3
// let [a3, b3, c3] = [1, , 3, ]
// console.log(a3, b3, c3); //1 undefined 3
// let [a4, b4] = [1];
// console.log(a4, b4); //1 undefined
// let {
// y: a5,b5
// } = {
// x: 1,
// y: 2
// };
// console.log(a5, b5); //2 undefined
// let {
// a6,
// b6
// } = 123;
// console.log(a6, b6); //undefined undefined
//因为a6, b6是对象, 要用键值对的方式进行赋值
//4、
// let set = new Set();
// set.add(1);
// set.add(2);
// set.add(3);
// set.delete(2);
// let i = set.values();
// console.log(i.next());//{value: 1, done: false}
// console.log(i.next());//{value: 3, done: false}
// console.log(i.next());//{value: undefined, done: true}
//5、
// let map = new Map();
// map.set(1, "a");
// map.set(2, "b");
// map.set(3, "c");
// map.set(4, "d");
// for (let i = 1; i <= map.size; i++) {
// console.log(map.get(i));
// }
// map.forEach(function(value, key) {
// console.log(value);
// });
// for (let v of map.values()) {
// console.log(v);
// }
// for (var prop in map) {
// console.log(prop);
// }
/* for-in循环实际是为循环”enumerable“对象而设计的,是用来循环带有字符串key的对象的。
    使用for in会遍历数组所有的可枚举属性,包括原型。*/
//6、
function showNews(title, content, date, tmp) {
let out;
//1号模板
if (tmp == 1) {
out =
`<h2>${title} <span style = "font-size = 12px">发布日期:${date}</span></h2>
<hr style = "border:1px #000 dashed;border-bottom:0px;"/>
<p>
<img src = "https://picsum.photos/200/100" style = "float:left;"hspace = "5px"/>
${content}
</p>`
}
//2号模板
else if (tmp == 2) {
out =
`<h2>${title}</h2>
<h5 style = "font-size = 12px;"> 发布日期:${date}</h5>
<hr style = "border:1px #000 dashed;border-bottom:0px;"/>
<div style = "text-align: center;">
<img src = "https://picsum.photos/200/100"></div>
<p>${content}</p>`
}
//3号模板
else {
out =
`<h2 style = "text-align: center;">${title}</h2>
<h5 style = "font-size = 12px;"></h5>
<hr style = "border:1px #000 dashed;border-bottom:0px;"/>
<div style = "text-align: center;">
<img src = "https://picsum.photos/200/100"></div>
<p>${content}</p>
<p style = "float:right";> 发布日期:${date}</p>`
}
document.write(out);
}
var news1 = {
title: "重庆市公共场所控制吸烟条例预计今年进入初审",
content: "《重庆市人大常委会2020年立法计划》已于市五届人大常",
date: new Date().toLocaleDateString()
}
//showNews(news1.title,news1.content,news1.date,1);//1号模板
var news2 = {
title: "重庆市公共场所控制吸烟条例预计今年进入初审",
content: "《重庆市人大常委会2020年立法计划》已于市五届人大常",
date: new Date().toLocaleDateString()
}
//showNews(news1.title,news1.content,news1.date,2);//2号模板
showNews(news1.title,news1.content,news1.date,3);//3号模板
</script>
</body>
</html>
1
https://gitee.com/mengmeng111/website.git
git@gitee.com:mengmeng111/website.git
mengmeng111
website
我的个人网站
master

搜索帮助