输入字数的限制和数字的加减效果 动态显示

原创 17858834814 随笔 随便写 232阅读 2017-05-10 18:03:41 举报

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="https://fonts.googleapis.com/css?family=Pacifico"; rel="stylesheet">
<script type="text/javascript" src="js/jquery.min.js" ></script>
</head>
<body>

    <textarea class="wtbt"  maxlength="50" onkeyup="javascript:setShowLength(this, 50, 'cost_tpl_title_length');"></textarea>
    <span><span id="id2">0</span>/<span id="cost_tpl_title_length">50</span></span>
</body>
<script>
     function setShowLength(obj, maxlength, id) 
        { 
            var rem = maxlength - obj.value.length; 
            var wid = id; 
            var rem1=obj.value.length;
            if (rem < 0){ 
            rem = 0; 
            } 
            document.getElementById(wid).innerHTML =rem; 
            document.getElementById("id2").innerHTML =rem1; 
        } 
</script>

</html>

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复