마우스 오버시 동적으로 하이퍼 링크를 만들고 mouseout 이벤트에서이를 제거 할 수 있어야합니다. 그러나 마우스가 링크 위로 이동하면 이 아닌은 마치 mouseout 인 것처럼 동작합니다. 이런 일이 발생하면 이벤트는 무한 루프가됩니다. 아래 예를 참조하십시오.자바 무한 루프로 들어가는 이벤트
<html>
<head><title>
</title></head>
<body>
<script language="javascript" type="text/javascript">
function showEdit(tcell) {
var editTag = document.createElement('a');
editTag.appendChild(document.createTextNode("test2"));
editTag.setAttribute('name', 'test2');
editTag.setAttribute('id', 'lnkEdit');
editTag.setAttribute('href', '#');
editTag.setAttribute('style', 'float:right;');
tcell.appendChild(editTag);
}
function hideEdit(tcell) {
//var tcell = document.getElementById("tcAdd");
var lnk = document.getElementById("lnkEdit");
tcell.removeChild(lnk);
}
</script>
<div>
<table style="width:200px;">
<tr>
<td id="tcAdd" style="border:1px solid #CCC" onmouseover="showEdit(this);" onmouseout="hideEdit(this);">
<a href="#">test1</a>
</td>
</tr>
</table>
</div>
</body>
</html>
커서를 test1 및 test2에 놓고 차이점을 확인하십시오. 나는 명백한 무엇인가 놓치고 있다고 생각합니다.
감사
[부모 절대 div의 자식 요소를 가리키면 onmouseout을 방지 할 수 있습니다.] (http://stackoverflow.com/questions/4697758/prevent-onmouseout -when-hovering-child-of-the-parent-absolute-div) –
고마워 할 것입니다. – Samuel