DOM3 textInput事件-softbar

來源:互聯網
上載者:User

DOM3中引入了文本事件,其中之一 textInput 。

 

當使用者再可編輯區域輸入字元時觸發該事件。

 

與keypress不同的是,該事件只會在使用者輸入可視字元時觸發,而keypres事件則只要按下鍵即觸發(如CapsLock,Backspace)。

 

可看到textInput考慮的主要是字元,可以通過事件對象的data屬性擷取所輸入字元。softbar

http://www.softbar.com/ 

 

樣本

01

<!DOCTYPE HTML>

02

<html>

03

<head>

04

<title>DOM3 event textInput</title>

05

</head>

06

<body>

07

 

08

<input id="ipt" type="text" />

09

<script type="text/javascript">

10

    function addEvent(el,type,fn){

11

        if(el.addEventListener){

12

            el.addEventListener(type, fn, false);

13

        }else{

14

            el.attachEvent('on' + type, fn);

15

        }      

16

    }

17

    var ipt = document.getElementById('ipt');

18

    addEvent(ipt,'textInput',function(e){

19

        e = e || window.event;

20

        console.log(e.data);

21

    });

22

</script>

23

 

24

</body>

25

</html>

 

目前只有IE9,Chrome,Safari支援。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.