contentEditable游标的父元素 [英] contentEditable cursor's parent element

查看:85
本文介绍了contentEditable游标的父元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个contentEditable HTML元素。我想获取光标的父元素。例如,如果光标在表格单元格内,我想显示一些用于编辑表格的控件。这可能吗?还是我要跟踪所有按键和鼠标的按下次数?

I have a contentEditable HTML element. I would like to get the cursor's parent element. For example, if the cursor is inside a table cell, I would like to display some controls for editing the table. Is this possible? Or am I going to track all key and mousepresses?

推荐答案

示例,使用 parentNode

document.getElementById('editable').onclick = function () {
 alert(this.parentNode.id);   
}

这篇关于contentEditable游标的父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆