textArea實時顯示文本輸入框輸入的字數

這裏寫圖片描述

<!DOCTYPE html>
<html>
<head>
    <title>TextArea</title>
    <meta charset="utf-8">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
</head>
<body>
    <textarea id="text">

    </textarea>
    <span id="num">0</span>
    <script type="text/javascript">
        window.onload = function(){
            $("#text").on('input propertychange',function(e){
                $("#num").html(e.target.value.length);
            });
        }
    </script>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章