简体   繁体   English

字段中保存的值的Javascript状态?

[英]Javascript state for saved values in fields?

I'm using a javascript library to move field labels into the field itself. 我正在使用JavaScript库将字段标签移到字段本身中。 When the user starts typing in the field, they fade out. 当用户开始在该字段中输入内容时,它们会淡出。 However, when the user has saved their username/password in the fields, the library isn't smart enough not to put the labels in the fields, so the text of the label is overrun with the username or the obfuscated password. 但是,当用户将用户名/密码保存在字段中时,该库不够智能,无法将标签放在字段中,因此标签文本会被用户名或混淆的密码所覆盖。

Is there a state of the pre-populated fields I could query with javascript to selectively disable moving the labels into the fields? 我可以使用javascript查询以选择性地禁用将标签移动到字段中的预填充字段的状态吗?

Edit this is the library that I'm using: In-Field Labels jQuery Plugin 编辑这是我正在使用的库: 现场标签jQuery插件

I see that there has been a vote to close this question because it is unclear. 我看到有人投票结束这个问题,因为目前尚不清楚。 Let me try to be more clear. 让我尝试更加清楚。 When the page loads, there is a saved username and password in the username and password fields. 页面加载后,用户名和密码字段中将保存一个用户名和密码。 I am wondering if there is some property on these fields that will tell me if they are populated with saved values when the page finishes loading. 我想知道这些字段上是否有一些属性可以告诉我在页面完成加载后是否使用保存的值填充它们。 If this is unclear please ask a clarifying question. 如果不清楚,请问一个澄清的问题。

The reason I want to know this is because I am using a javascript library that puts a field's label visually within its field, so you get [Username____] instead of Username [________] . 我想知道这一点的原因是因为我正在使用一个JavaScript库,该库将字段的标签可视地放在其字段中,所以您得到了[Username____]而不是Username [________] The problem is when the browser has saved the username, then the text "Username" in the field runs over the saved username also in the field. 问题是当浏览器保存了用户名时,字段中的文本“ Username”越过了该字段中保存的用户名。 I want to stop the moving of the field label into the field only if there is a value already in it. 我只想在其中已经有值的情况下停止将字段标签移到字段中。 So I am looking for a way I can tell if the field is pre-populated. 因此,我正在寻找一种方法来判断该字段是否已预先填充。

I think what you are talking about is a PlaceHolder attribute : 我认为您正在谈论的是PlaceHolder属性:

A hint to the user of what can be entered in the control . 向用户提示可以在控件中输入的内容。 The placeholder text must not contain carriage returns or line-feeds. 占位符文本不得包含回车符或换行符。 This attribute applies when the value of the type attribute is text, search, tel, url or email; 当type属性的值为text,search,tel,url或email时,此属性适用。 otherwise it is ignored. 否则将被忽略。

See this JSFiddle : 看到这个JSFiddle

<input type="text" placeholder="label"/>

For a cross browser compatibility, see this plugin : https://github.com/mathiasbynens/jquery-placeholder 有关跨浏览器的兼容性,请参见以下插件: https : //github.com/mathiasbynens/jquery-placeholder

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

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