Jquery limit text in input box

前端 未结 2 2011
你的背包
你的背包 2021-01-08 00:45

I want to limit number of chars in input text field.

Code I\'m using:

function limitText(field, maxChar){
    if ($(field).val().length > maxChar)         


        
2条回答
  •  [愿得一人]
    2021-01-08 01:28

    you can also do it like this:

    
    

    to achieve this with jQuery, you can do this:

    function limitText(field, maxChar){
        $(field).attr('maxlength',maxChar);
    }
    

提交回复
热议问题