亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery 鍵盤事件之 keydown()和keyup()事件

keydown()事件

定義和用法

完整的 key press 過程分為兩個(gè)部分:1. 按鍵被按下;2. 按鍵被松開。

當(dāng)按鈕被按下時(shí),發(fā)生 keydown 事件。

keydown() 方法觸發(fā) keydown 事件,或規(guī)定當(dāng)發(fā)生 keydown 事件時(shí)運(yùn)行的函數(shù)。

注釋:如果在文檔元素上進(jìn)行設(shè)置,則無論元素是否獲得焦點(diǎn),該事件都會發(fā)生。

語法

$("").keydown()

下面我們來寫一個(gè)keydown事件

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>submit</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>    
    <p>php 中文網(wǎng)</p>

    <script>
        $('body').keydown(function(){
            $('p').html('php.cn');
        })
    </script>
</body>
</html>

當(dāng)按下鍵盤時(shí),“php 中文網(wǎng)”會被替換成“php.cn”

keyup 事件

定義和用法

完整的 key press 過程分為兩個(gè)部分,按鍵被按下,然后按鍵被松開并復(fù)位。

當(dāng)按鈕被松開時(shí),發(fā)生 keyup 事件。它發(fā)生在當(dāng)前獲得焦點(diǎn)的元素上。

keyup() 方法觸發(fā) keyup 事件,或規(guī)定當(dāng)發(fā)生 keyup 事件時(shí)運(yùn)行的函數(shù)。

注釋:如果在文檔元素上進(jìn)行設(shè)置,則無論元素是否獲得焦點(diǎn),該事件都會發(fā)生。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>    
    <p>php 中文網(wǎng)</p>

    <script>
        $('body').keyup(function(){
            $('p').html('php.cn');
        })
    </script>
</body>
</html>

看如上實(shí)例,大家可以在本地調(diào)試,當(dāng)按下鍵盤并沒有松開鍵盤,文本不會發(fā)生改變,當(dāng)鍵盤松開時(shí),文本發(fā)生變化

Weiter lernen
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>submit</title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <p>php 中文網(wǎng)</p> <script> $('body').keydown(function(){ $('p').html('php.cn'); }) </script> </body> </html>
einreichenCode zurücksetzen