https://www.runoob.com/try/try.php?filename=tryjsref_node_removechild
document.addEventListener('visibilitychange', () => {
document.title = document.hidden
? '用户离开了' + document.hidden
: '用户回来了' + document.hidden
})
;<div contenteditable="true" />
const imgSrc = require(`@/assets/img/emoji/${hoverPath}`)
const imgTag = `<img src="${imgSrc}" width="28" height="28" alt="${info}">`
document.execCommand('insertHTML', false, imgTag)
const containerDom = document.getElementById('container') //需要调整尺寸的div
containerDom.addEventListener('mousedown', mousedown) // 鼠标按下事件
function mousedown(event) {
const direction = getDirection(event)
// 当位置为四个边和四个角时才开启尺寸修改
if (direction !== '') {
resizeable = true
direc = direction
clientX = event.clientX
clientY = event.clientY
}
}
document.addEventListener('mouseup', mouseup) // 鼠标松开事件
// 鼠标松开时结束尺寸修改,重置是否开启尺寸修改及方向
function mouseup() {
resizeable = false
direc = ''
}
window.addEventListener('onunload', () => {
// 执行旧页面代码
})
window.addEventListener('pageshow', e => e.persisted && location.reload())
Safari 浏览器用 YYYY/MM/DD HH:mm:ss 这种日期格式, 然而接口返回字段的日期格式通常是 YYYY-MM-DD HH:mm:ss,那么需替换其中的-为/。
new Date('2019-03-31 21:30:00') // Invalid Date ,错误
// 正确
const date = '2019-03-31 21:30:00'
new Date(date.replace(/\-/g, '/'))
const input = document.getElementById('input')
let scrollTop = 0
input.addEventListener('focus', () => {
scrollTop = document.scrollingElement.scrollTop
})
input.addEventListener('blur', () => {
document.scrollingElement.scrollTo(0, scrollTop)
})
// 解决方案1:使用input事件代替输入框的keyup/keydown/keypress事件
// 即 @input