简体   繁体   English

Django中有没有一种方法可以使单击带有初始文本的表单时该文本消失?

[英]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. 查看Django文档 ,了解有关如何从Django Forms中自定义HTML的更多信息。

您需要为此使用html:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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