html標(biāo)簽中的this使用介紹

字號:


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