如何删除从标签接管的密码字段上的占位符

发布于 2024-11-26 12:12:16 字数 926 浏览 2 评论 0原文

我无法删除密码文本框中不需要的占位符(或水印)。当密码文本框获得焦点时,Android Web 浏览器会显示从关联标签元素取代的占位符,如下所示:

在此处输入图像描述

HTML 源:

<form method="post">
    <label for="userName">Login name:</label>
    <input id="userName" name="userName" type="text" value="" />

    <label for="password">Password:</label>
    <input id="password" name="password" type="password" />

    <input type="submit" id="submit" name="submit" value="Log In" />
</form>

注意:

  • 仅当文本框具有焦点且为空时才显示占位符。
  • 当在密码输入上使用“占位符”HTML 属性时,它仅在密码获得焦点之前显示。当它获得焦点时,它会显示标签文本。
  • 我不想删除标签的“for”属性。我希望标签可单击,并且密码文本框在单击标签时获得焦点。

编辑:

尝试了另一种变体(避免了“for”属性),但占位符仍然存在:

<label>Password: <input id="password" name="password" type="password" /></label>

I can't get rid of unwanted placeholder (or watermark) on password textbox. When password textbox is focused, Android web browser displays placeholder overtaken from associated label element, like this:

enter image description here

HTML source:

<form method="post">
    <label for="userName">Login name:</label>
    <input id="userName" name="userName" type="text" value="" />

    <label for="password">Password:</label>
    <input id="password" name="password" type="password" />

    <input type="submit" id="submit" name="submit" value="Log In" />
</form>

Note:

  • Placeholder is displayed only when the textbox has focus and is empty.
  • When using "placeholder" HTML attribute on password input, it is displayed only until the password gets focused. When it receives focus, it displays label text instead.
  • I don't want to delete the "for" attribute of the label. I want the label to be clickable and the password textbox to get focus when the label is clicked.

Edit:

Tried another variant (which avoids "for" attribute), but the placeholder is still present:

<label>Password: <input id="password" name="password" type="password" /></label>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冷血 2024-12-03 12:12:16

以下 css 可以禁用此功能:

-webkit-user-modify: read-write-plaintext-only;

the following css can disable this:

-webkit-user-modify: read-write-plaintext-only;
自此以后,行同陌路 2024-12-03 12:12:16

我认为你需要 android 中的占位符。为此,请使用 Edittext 的属性

android:hint="用户名"

<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textNoSuggestions" android:id="@+id/textName" android:hint="Username"></EditText>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:id="@+id/textEmail" android:hint="Email"></EditText>

I think you need the place holder in android. For that use the property of Edittext

android:hint="Username"

<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textNoSuggestions" android:id="@+id/textName" android:hint="Username"></EditText>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:id="@+id/textEmail" android:hint="Email"></EditText>
宛菡 2024-12-03 12:12:16

为防止这种情况,您需要做的是将标签“for”属性设置为“password”以外的其他内容。您还可以将输入的“名称”属性更改为“密码”以外的其他内容。两者似乎都阻止 Android 将标签作为占位符放入。

What you need to do to prevent this is to set the label 'for' attribute to be something other than 'password'. You can also change the 'name' attribute of the input to something other than 'password'. Both seem to stop Android from putting the label in as a placeholder.

硪扪都還晓 2024-12-03 12:12:16

似乎不可能在“聚焦”密码字段上应用样式,因为实际上它是绝对位于原始输入之上的另一个输入实例。因此,当密码字段处于焦点状态时,有两个字段。

我已经在 J​​avaScript 的帮助下成功删除了这段文本。
这个想法是暂时删除相应的

代码如下所示:

var field = document.getElementById('password');
var label = document.querySelector('label[for="password"]');
field.onfocus = function() {
    label.parentNode.removeChild(label);
    setTimeout(function(){
        field.parentNode.insertBefore(label, field);
    },1000);
}

setTimeout 的小延迟不起作用。我认为延迟是特定于设备/系统的。
也许修改 label.innerHTML 或其他一些技巧也可以帮助删除此文本;)

It seems that it's impossible to apply styles on "focused" password field because actually it is another input instance absolutely positioned over the original input. So there are two fields when password field in focus.

I've managed to remove this text with the help of JavaScript.
The idea is to temporary remove corresponding <label> from DOM, and then restore it after while.

The code will look like:

var field = document.getElementById('password');
var label = document.querySelector('label[for="password"]');
field.onfocus = function() {
    label.parentNode.removeChild(label);
    setTimeout(function(){
        field.parentNode.insertBefore(label, field);
    },1000);
}

Small delay for setTimeout is not working. I think delay for this is device/system specific.
Maybe modifing label.innerHTML or some other tricks also can help to remove this text ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文