老师看一下

来源:2-4 编程练习

慕少5306396

2020-06-15 16:47:55

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>模版字符串</title>

</head>


<body>

<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>

<script type="text/javascript">

const tmpl = function() {

return {

title: "前端",

data: [{

title: '布局基础',

date: ["html", "css"]

}, {

title: '网页特效',

date: ["javascript", "jquery"]

}, {

title: '框架',

date: ["bootstrap", "vue"]

}]

}

}

// 补充代码

const {title,data:datalist} = tmpl;

let arr = [];

arr.push(`<caption>${title}</caption>`);

datalist.forEach(function({title,date}){

arr.push(`

         <tr>

           <td>${this.title}</td>

           <td>${this.date[0]}</td>

           <td>${this.data[1]}</td>

         </tr>

       `);

});

var table = document.createElement('table');

table.innerHTML = arr.join('');

document.body.appendChild(table);

table.style.textAlign ="center";

table.border = 1;

</script>

</body>

</html>


写回答

1回答

好帮手慕夭夭

2020-06-15

同学你好,代码的问题与修改如下:

1.tmpl的值是一个函数,函数需要调用才会执行。如下加括号调用,然后就能得到函数的返回值了。

http://img.mukewang.com/climg/5ee739140946f25704800084.jpg

2.参数使用时,不需要加this。最后一个单词拼错,改成date。如下:

http://img.mukewang.com/climg/5ee7396809fc2b1505620279.jpg

如果我的回答帮到了你,欢迎采纳,祝学习愉快~

0

0 学习 · 10739 问题

查看课程

相似问题