JavaScript學習-事件處理

來源:互聯網
上載者:User

如何編寫事件處理常式方法:
    方法1、在事件來源對象所對應的Html標籤上增加要處理事件屬性,讓事件屬性值等於處理該事件的函數名或程式碼。
    方法2、JavaScript代碼中,設置元素對象的事件屬性,讓事件屬性值等手處理該事件的函數名或程式碼。
    方法3、在一個專門的<script>標答對中編寫某個元素對象的某種事件處理常式代碼,並用for屬性指定事件來源和用event屬性指定事件名

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>無標題頁</title>
    <script type="text/javascript" language="JavaScript">    
        function funDisableRight()
        {
            //禁用右鍵
            window.event.returnValue=false;           
        }
    </script>
    

    <!-- 此處屬於第二種方法
        <script type="text/javascript" language="javascript" >
        document.oncontextmenu=hideContextMenu;
        function hideContextMenu()
        {
            return false;
        }  
        </script>
    -->
    
   <!-- 此處屬於第三種方法
        <script type="text/javascript" language="javascript" for="document" event="funDisableRight">
        </script>
    -->
    
</head>
<!--此處屬於第一種方法-->
<body oncontextmenu="funDisableRight();">
    <form id="form1" runat="server">
        <div>
        </div>
    </form>
</body>
</html>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.