Prototype – 事件 element() 方法

返回到:Prototype – 事件处理

此方法返回发生事件的 DOM 元素。

语法

Event.element();

返回值

返回发生事件的 DOM 元素。

例子

这是一个简单的代码,可以让您点击页面上的任何地方,如果您直接点击段落,隐藏它们。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         // Register event 'click' and associated call back.
         Event.observe(document, 'click', respondToClick);
  
         // Callback function to handle the event.
         function respondToClick(event) {
            var element = event.element();
            alert("Tag Name : " + element.tagName );
            
            if ('P' == element.tagName) {
               element.hide();
            }
         }
      </script>
   </head>

   <body>
      <p id = "note"> Click on any part to see the result.</p>
      <p id = "para">This is paragraph</p>
      <div id = "division">This is divsion.</div>
   </body>
</html>

返回到:Prototype – 事件处理

作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8561.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年1月31日
下一篇 2023年2月1日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注