今天继续学习JavaScript的第二天,还是打基础
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><p id="demo"></p><button onclick="demo1()">点击一下</button><p id="demo2"></p><p id="demo3"></p><button onclick="fun()">constructor属性的运用··</button><script type="text/javascript">// ``表示模板字符串的运用,不用使用转义字符来区分单引号还是双引号的使用let name = `I'am zhangsan is a "handsameboy"`;document.getElementById("demo").innerHTML = name;// 模板字符串当中的占位符,可以使用${}的表达式在里面添加内容,并运行其中的值const name1 = "Ryan";const city = "jiangsu";function demo1() {alert(`my name is ${name1},I come from ${city}.`);}// 使用模板字符串当作HTML使用let header = "名单列表";let html = `<h1>${header}</h1><ul>`;let array = ['xiaoming', 'zahngsan', 'libai'];for (x in array) {html += `<li>${x}</li>`;}html += `</ul>`;document.getElementById("demo2").innerHTML = html;// JavaScript中的switch的用法:记得里面的case后面一定要加入breakvar d = new Date().getDay();switch (d) {case 0: x = "今天星期日";break;case 1: x = "今天星期一";break;default: x = "放假";}document.getElementById("demo3").innerHTML = x;// 使用constructor属性返回变量或对象的构造函数function fun() {let name = "xiaoming"console.log(name.constructor)}</script>
</body></html>
里面有备注的地方,欢迎大家快来支持!!!!!