HTML-事件

<body>
    <input type="button" value="Click Me" onclick="alert('Clicked')" />
    <input type="button" value="Click Me" onclick="alert("Clicked")" />
    <script type="text/javascript">
        function showMessage(){
            alert("Hello world!");
        }
    </script>
    <input type="button" value="Click Me" onclick="showMessage()" />
    <input type="button" value="Click Me" onclick="try{showMessage();}catch(ex){}" />
    <input type="button" value="Click Me" onclick="alert(event.type)">
    <!-- outputs "Click Me" -->
<input type="button" value="Click Me" onclick="alert(value)">

<!-- outputs "Click Me" -->
<input type="button" value="Click Me" onclick="alert(this.value)">
<form method="post">
    <input type="text" name="username" value="enter username">
<!-- 这样使用需要在 form 表单里面 -->
    <input type="button" value="Echo Username" onclick="alert(username.value)">
</form>
</body>