简体   繁体   中英

Is there a way in Django to make it so that when a form with initial text is clicked the text disappears?

For example, on some sites in the username form box it says something like "username" and then when you click there the "username" disappears so you can type your username.

Thanks.

Yes, you can do this in a form.

Username =forms.CharField(max_length=35,
                          required=True, 
                          widget=forms.TextInput(attrs={'placeholder': 'Username'}))

Check out the Django Docs for more on how to customize HTML from Django Forms.

您需要为此使用html:

<input type="text" placeholder="This text will disappear" />

我认为您正在寻找占位符属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM