onChange 이벤트에 바인딩하는 것은 괜찮은 것처럼 보이지만 onKey --- 이벤트도 고려해야합니다. 나는 다음과 같은 코드가 당신을 위해 도움이 될 것입니다 희망 :
CSS는 (content_css 즉 정의 할 수) :
[current] {
background-color:yellow;
}
[changed] {
background-color:green;
}
JS의 helpfunctions :
var select_current = function(node){
unselect_current();
node.setAttribute('current','true');
};
var unselect_current = function(){
var n = ed.getBody().firstChild;
while (n){
if (n.nodeType == 1 && n.getAttribute('current'))
{
n.removeAttribute('current');
}
n = n.nextSibling;
}
};
p_of = function(node) // returns p-Element of node
{
while (node){
if (node.nodeName == 'BODY') { return null; }
if (node.nodeName == 'P') { return node; }
else { node = node.parentNode; }
}
return null;
}
이벤트 통화 :
을
var _node_changing = false;
console.log('onNodeChange: ', arguments);
if (!_node_changing && element.getAttribute('_mce_type') != 'bookmark'){
_node_changing = true;
var p = p_of(element);
if (p){
if (!p.getAttribute('current')){
select_current(p);
}
}
_node_changing = false;
}