mousecapture.htm

来自「Windows Web脚本开发指南/(美) Dan Heflin, Todd N」· HTM 代码 · 共 35 行

HTM
35
字号
<html>
<script>
var activeMenu = null;
function displayMenu(){
  if (event.srcElement == menu){
    if (activeMenu == null){
      newElement = document.createElement("DIV");
      newElement.style.width = 100;
      newElement.style.backgroundColor = "lightblue";
      newElement.innerHTML = "New";  
      body.appendChild(newElement);
      menu.setCapture(true);
      activeMenu = newElement;
    }
  }
  else
    if (event.srcElement == activeMenu)
      alert("The New menu has been clicked");
    else 
      menu.releaseCapture();
}
function closeCapture(){
  body.removeChild(activeMenu);  
  activeMenu = null;
}
</script>
<body id="body">
<p>Click on the File Menu above to see the child element</p>
<DIV id="menu" onloseCapture="closeCapture()" onClick="displayMenu()" 
style="background:lightblue">File</DIV>
</body>
</html>


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?