(() => {
let list = ['学习了', '谢谢楼主', '紫薯布丁'];
let c = t => document.createElement(t);
let s = t => document.querySelector(t);
let ta = s('textarea');
if(!ta) return;
let box = c('div');
box.style.position = 'absolute';
box.style.display = 'none';
box.style.background = 'rgba(230, 230, 230, 0.4)';
box.style.borderRadius = '0.2em';
for (let i of list) {
let p = c('p');
p.innerText = i;
p.style.color = '#333';
p.style.margin = '0.5em 1em';
p.style.cursor = 'pointer';
p.onclick = () => {
ta.value = ta.value + i;
box.style.display = 'none';
};
box.appendChild(p);
}
document.body.appendChild(box);
ta.oncontextmenu = e => {
e.preventDefault();
console.log(e);
let { pageX, pageY } = e;
box.style.top = pageY + 'px';
box.style.left = pageX + 'px';
box.style.display = 'block';
}
})();
// 根据楼主的描述写了一个