閲覧いただきありがとうございます。
文字数カウントを実装することになったのですが、マイナス値での表記が気に入らないとお客様に言われてしまいまして。。
みなさんのお力をお借りできたらと思います。
お手数をおかけしますが、よろしくお願いいたします。
できていること
入力フォームに入力された文字数と上限を比べて入力文字数がカウントされていく
実現したいこと
現状は、countDownという変数を表示しているのでマイナス値になった時に「-1文字入力可能」と言った感じに出てきてしまいます。
そうではなく、「1文字オーバー」などの表記にしたいです。
ソース
html
1<input type="text" id="productlocation_name" name="productlocation_name" with="full" limit="20" value=""> 2<span class="count_input"></span>
javascript
1$("[limit]").bind('keydown keyup keypress change',function(){ 2 var limit = $(this).attr("limit"); 3 var thisValueLength = $(this).val().length; 4 var countDown = (limit)-(thisValueLength); 5 $(this).nextAll(".count_input").html(countDown + "文字入力可能"); 6 7 if(countDown < 0){ 8 $(this).nextAll(".count_input").css({color:'#ff0000',fontWeight:'bold'}); 9 $(this).nextAll(".count_input").html(countDown + "文字オーバー"); 10 } else { 11 $(this).nextAll(".count_input").css({color:'#000000',fontWeight:'normal'}); 12 $(this).nextAll(".count_input").html(countDown + "文字入力可能"); 13 } 14 }); 15 16 $(window).load(function(){ 17 $(this).nextAll(".count_input").html(limit); 18 });
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/20 06:09
2018/06/20 06:24
2018/06/21 02:14