// 内容
var text = ‘’
// 贴贴数据
var clp = (e.originalEvent || e).clipboardData
// 贴贴内容
if (clp && clp.getData) {
text = clp.getData(‘text/plain’) || ‘’
} else if (window.clipboardData && window.clipboardData.getData) {
text = window.clipboardData.getData(‘text’) || ‘’
}
// 内容不为空
if (text !== ‘’) {
// 数据是否满足指定格式
if (clp === undefined || clp === null) {
// 是否有光标位置
if (window.getSelection) {
// 有则插入指定位置
var newNode = document.createElement(‘span’)
newNode.innerHTML = text
window.getSelection().getRangeAt(0).insertNode(newNode)
} else {
// 没有则直接贴贴
document.selection.createRange().pasteHTML(text)
}
// 需要手动调用 oninput 输入事件
} else {
// 插入内容,会自动调用 oninput 输入事