3

在 Android 布局 xml 文件中,可以执行以下操作...

<EditText android:id="@+id/username"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/username" />
<EditText android:id="@+id/password"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:hint="@string/password" />

这会产生一个如下所示的 GUI:截屏

如何使用 CSS 为 HTML 表单创建相同的效果?

4

1 回答 1

5

您可以使用placeholderHTML5 属性,例如:

<input type="text" name="username" placeholder="Username" />
<input type="text" name="password" placeholder="Password" />

大多数浏览器都与此功能兼容,除了 Internet Explorer(请参阅 jcater 的评论)。例如,您可以使用jquery-placeholder添加对旧版浏览器(甚至 IE6!)的支持。

于 2012-09-11T03:47:58.490 回答