请老师检查
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>模版字符串</title> </head> <body> <div class="div1"></div> <script type="text/javascript"> let person = { name: "xiaoming", age: 18, }; let elem = document.querySelector(".div1"); elem.innerHTML = "He is <b>" + person.name + " </b> " + "and we wish to know his" + person.age + ".That is all<br>"; document.write(person); document.write("<br>"); document.write("<br>"); let add = `He is <b>${person.name}</b>, and we wish to know his${person.age}.That is all`; document.write(add); </script> </body> </html>
8
收起
正在回答
1回答
同学你好,模板字符串写的是对的,有一个问题需要注意:使用document.write打印对象时,会将对象转成字符串形式输出,即会变成[object Object]:
所以对象不要使用document.write输出,建议使用console.log()输出。
祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星