키 이벤트를 발생시키지 않으므로 링크 자체에서 키 이벤트를 감지 할 수 없습니다. 대신, contenteditable 요소에 대한 기존 keypress
처리기를 적용하여 선택 항목을 검사하여 링크 내에 있는지 확인해야합니다. 이를 수행하는 함수가 있습니다. 나도 updated your demo입니다.
function selectionInsideLink() {
var node = null, sel;
// Get the selection container node
if (window.getSelection) {
sel = window.getSelection();
if (sel.rangeCount) {
node = sel.getRangeAt(0).commonAncestorContainer;
}
} else if (document.selection) {
sel = document.selection;
if (sel.type != "Control") {
node = sel.createRange().parentElement();
}
}
// Check if the node is or is contained inside a link
while (node) {
if (node.nodeType == 1 && node.tagName.toLowerCase() == "a") {
return true;
}
node = node.parentNode;
}
return false;
}
나는 당신이 내 영웅이라고 말했습니까? 나는 범위가 넓어서 선택하기에 매우 도움이된다. 감사. – daveyfaherty