How can I implement Stack Overflow-like watermarks in forms?

后端 未结 5 1823
天涯浪人
天涯浪人 2020-12-28 10:28

I remember seeing a tutorial somewhere that talks of how to style your input forms in a more “usable” way.

Essentially, you have a placeholder value and when you ent

5条回答
  •  鱼传尺愫
    2020-12-28 10:50

    In response to @Paul's post, I noticed the behavior of the HTML5 placeholder acts strangely on my Android emulator. The placeholder looks great until you click on it and it becomes black with your cursor to the right of the word. Granted, if you type it will disappear, but it's not intuitive. So I wrote some jQuery to fix it (where's my HTML5/jQuery badge?)

    $(document).ready(function() {
        $('input[placeholder]').focus(function() {
            if (!$(this).val()) $(this).val('');
        });
    });
    

提交回复
热议问题