Limit the number of characters in a separate input field for each character

后端 未结 4 476
说谎
说谎 2021-01-20 01:39

I have an input field and would want to give it a look and feel of a character-by-character box field (image below).

My HTML and CSS are written below. They

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 02:11

    Using some JS you can blur the input.

    Obs.: I did some adjusts in css..

    $(document).ready(function(){
    	$("#text").on('keypress', function(e){
      	if($(this).val().length > 4) {
        	var value = $(this).val() + String.fromCharCode(e.keyCode);
          $(this).val(value);
        	$(this).blur();
        }
      });
    });
    #text{
        background-image:
        url("http://3.bp.blogspot.com/-4oAWWCcNNz4/Tjr3nKNyVUI/AAAAAAAAPLU/Pouua-pNsEY/s1600/sq.gif");    
        width: 114px;
        height: 18px;
        background-size: 20px;
        border: none;
        font-family: monospace;
        font-size: 13px;
        padding-left: 6.5px;
        letter-spacing: 13px;
    }
    
    

提交回复
热议问题