How to set an input width to match the placeholder text width

前端 未结 4 1288
梦毁少年i
梦毁少年i 2020-12-08 18:39

Example http://dabblet.com/gist/5859946

If you have a long placeholder, the input by default does not display wide enough to show all the placeholder text.

e

4条回答
  •  醉酒成梦
    2020-12-08 19:07

    This can be done only via javascript by setting the size = placeholder length:

    input.setAttribute('size',input.getAttribute('placeholder').length);
    

    Here is a code that dose that for all the inputs: http://jsfiddle.net/KU5kN/

提交回复
热议问题