补全 innerHTML
This commit is contained in:
parent
5a39a2eb3d
commit
0865ef39f6
@ -1,15 +1,16 @@
|
||||
export function createElement({ innerText, textContent, readOnly, children = [], dataset, style, classList = [], ...attributes }, tagName = 'div') {
|
||||
export function createElement({ innerText, innerHTML, textContent, readOnly, children = [], dataset, style, classList = [], ...attributes }, tagName = 'div') {
|
||||
const element = document.createElement(tagName)
|
||||
for (const key in attributes) {
|
||||
if (key.startsWith('on')) element[key] = attributes[key] // 如果是事件则直接赋值
|
||||
else element.setAttribute(key, attributes[key]) // 否则是属性则使用setAttribute
|
||||
}
|
||||
if (dataset) Object.assign(element.dataset, dataset)
|
||||
if (style) Object.assign(element.style, style)
|
||||
if (classList.length) element.classList.add(...classList)
|
||||
if (textContent) element.textContent = textContent
|
||||
if (innerText) element.innerText = innerText
|
||||
if (innerHTML) element.innerHTML = innerHTML
|
||||
if (readOnly) element.readOnly = readOnly
|
||||
if (dataset) Object.assign(element.dataset, dataset)
|
||||
if (children) children.forEach(child => element.appendChild(child))
|
||||
return element
|
||||
}
|
||||
@ -95,14 +96,14 @@ export function UploadMusic(options) {
|
||||
console.log('dragover')
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
if(dragStats) return
|
||||
if (dragStats) return
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
drop.style.display = 'block'
|
||||
},
|
||||
ondragleave: event => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
if(dragStats) return
|
||||
if (dragStats) return
|
||||
clearTimeout(dragStats)
|
||||
dragStats = setTimeout(() => {
|
||||
drop.style.display = 'none'
|
||||
|
Loading…
Reference in New Issue
Block a user