jQuery - resizing form input based on value's width?

后端 未结 10 1336
挽巷
挽巷 2020-12-06 17:28

Is it possible to get input\'s value width and resize the input dynamically so the value will fit?

Here\'s an example:

http://jsfiddle.net/bzBdX/2/

10条回答
  •  再見小時候
    2020-12-06 17:43

    Current answers were waay to complicated. Heres a quick one

    $('#myinput').width($('#myinput').prop('scrollWidth'))
    

    Adding the above to input keydown/up/press events is trivial. Tested in chrome

提交回复
热议问题