How to create an HTML form with pre-filled in “instructions” that clear when a user clicks in the box?

后端 未结 5 1659
眼角桃花
眼角桃花 2021-02-13 10:27

I have an HTML form as follow:

   
Username: Passwor
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 11:26

    The feature you're looking for is called a "placeholder". (if nothing else, just knowing this term will help you search for more info in Google)

    In modern browsers which support HTML5, this is a built-in feature which you can use very easily, as follows:

    
    

    However, this method only works with up-to-date browsers which support this feature.

    Older browsers will need to have some Javascript code to do it. Fortunately, there are a number of scripts you can use, including some written as JQuery plug-ins. The ones I'd recommend are those which tie into the placeholder attribute on the input field, so that you can support it natively in the browsers which have this feature and fall-back to Javascript for those that don't.

    Try this one: http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html

提交回复
热议问题