Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 contentEditable HTML 元素。我想获取光标的父元素。例如,如果光标在表格单元格内,我想显示一些用于编辑表格的控件。这可能吗?还是我要跟踪所有的按键和鼠标按下?
使用parentNode的示例:
document.getElementById('editable').onclick = function () { alert(this.parentNode.id); }