在数组对像里面只拿到自己想要的值
var featrueTages = [
{ id: 1, name: 2, checked: '0' },
{ id: 2, name: 3, checked: '0' },
{ id: 3, name: 4, checked: '0' },
]
let newVar = []
for (let key in featrueTages) {
let { id, name } = featrueTages[key]
newVar.push({ id, name })
}
console.log(newVar)
异步加载图片
loadImageAsync('./imges/tupianzzz.png').then(res => {
console.log(res);
}).catch(error => {
throw new Error(error)
})
function loadImageAsync(url) {
return new Promise(function (resolve, reject) {
const img = new Image();
img.src = url
img.id = "img"
img.onclick = function () {
console.log("点击了");
}
img.click()
img.onload = function () {
let fchild = document.getElementById('img')
fchild.appendChild(img)
resolve(img)
}
img.onerror = function () {
reject("创建失败", url)
}
})
}