html標簽中的this使用介紹

字號:


    代碼如下:
    <html>
    <head>
    <script type="text/javascript">
    function showHint(str){
    alert(str) ;
    }
    </script>
    </head>
    <body>
    <input type="text" onkeyup="showHint(this.value)"/> <!--此處,在html標簽中的this代表的是此標簽-->
    </body>
    </html>
    運行結(jié)果為:當通過鍵盤向文本框中輸入字符后,當按鍵抬起時(即當keyup事件發(fā)生后),會顯示按下的字符。