Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm adding an event listener to my paragraph element in Javascript.

(我在Java语言的段落元素中添加了事件监听器。)

My paragraphs are inside my 'main' HTML element.

(我的段落在我的“主要” HTML元素内。)

when the user presses the keyboard button 'AltGr' (key code 18) the paragraph is supposed to become a child of its predecessor.

(当用户按下键盘按钮“ AltGr”(键代码18)时,该段落应成为其前身的子代。)

But the event itself isn't firing.

(但是事件本身并没有触发。)

Why is this and how do I solve the problem?

(为什么会这样,我该如何解决呢?)

let m=document.getElementById('textEdit');

function pKeyClick(e){
if (e.keyCode=="18"){ //AltGr
    e.preventDefault();
    let parent=m.childNodes[m.childNodes.length-2];
    let li=document.createElement("li");
    m.replaceChild(li,e.target);
    parent.appendChild(ul);
    console.log(parent.childNodes)
    e.stopPropagation();
  }
}

The event gets attached whenever p is generated.

(每当生成p时,事件就会被附加。)

  ask by jamie translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
462 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...