js部分

第一题

1
'undefined' in window; // true

说明
window有一个undefined属性,属性值为’undefined’; 该属性不允许修改的;
数据属性


第二题

写个函数返回一个页面里共使用了多少种HTML tag?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function tagSpecies() {
var tagCollect = document.getElementsByTagName('*'),
tags = {};

for (var i = 0; i < tagCollect.length; i++) {
tags[tagCollect[i].tagName] = tagCollect[i].tagName;
}
return (Object.keys(tags)).length;
}

function tagSpecies() {
function tagSpecies() {
let tags = [...document.getElementsByTagName('*')].map((v) => {
return v.tagName
})
tags = [...new Set(tags)];
return tags.length;
}
}

function tagSpecies() {
let html = document.documentElement;
let tags = ['html'];
function getTagesName (el) {
[...el.children].forEach((v) => {
tags.push(v.tagName)
if (v.children.length) {
return getTagesName(v)
}
})
}
getTagesName(html);
tags = [...new Set(tags)];
return tags.length;
}

第三题

1
2
3
4
5
6
for(var i = 0; i < 5; i++) {
setTimeout(function () {
console.log(i);
});
}
console.log('a');

详细讲解这里查看哦