【发布时间】:2017-06-17 12:32:30
【问题描述】:
一切正常我遇到了一点问题。我有两个字段电子邮件和密码。我的电子邮件 ID 和密码保存在浏览器中。当我点击 URL 时,我会在字段中自动填写电子邮件和密码,但我的占位符会覆盖字段记录。我必须在文本字段下方显示标签。请检查下图。
(function() {
// trim polyfill : https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
if (!String.prototype.trim) {
(function() {
// Make sure we trim BOM and NBSP
var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
String.prototype.trim = function() {
return this.replace(rtrim, '');
};
})();
}
[].slice.call(document.querySelectorAll('input.input__field')).forEach(function(inputEl) {
// in case the input is already filled..
if (inputEl.value.trim() !== '') {
classie.add(inputEl.parentNode, 'input--filled');
}
// events:
inputEl.addEventListener('focus', onInputFocus);
inputEl.addEventListener('blur', onInputBlur);
});
function onInputFocus(ev) {
classie.add(ev.target.parentNode, 'input--filled');
}
function onInputBlur(ev) {
if (ev.target.value.trim() === '') {
classie.remove(ev.target.parentNode, 'input--filled');
}
}
})();
<script src="https://tympanus.net/Development/TextInputEffects/js/classie.js"></script>
<link href="https://tympanus.net/Development/TextInputEffects/css/normalize.css" rel="stylesheet" />
<link href="https://tympanus.net/Development/TextInputEffects/css/set2.css" rel="stylesheet" />
<link href="https://tympanus.net/Development/TextInputEffects/css/demo.css" rel="stylesheet" />
<section class="content bgcolor-4">
<h2>Ruri</h2>
<span class="input input--ruri">
<input class="input__field input__field--ruri" type="email" id="input-26" />
<label class="input__label input__label--ruri" for="input-26">
<span class="input__label-content input__label-content--ruri">Email</span>
</label>
</span>
<span class="input input--ruri">
<input class="input__field input__field--ruri" type="password" id="input-27" />
<label class="input__label input__label--ruri" for="input-27">
<span class="input__label-content input__label-content--ruri">Password</span>
</label>
</span>
</section>
【问题讨论】:
-
您是否有理由让
placeholder同时用于email和password字段? -
感谢eeya先生的回复,我正在使用这个插件作为文本字段tympanus.net/Development/TextInputEffects/index2.html
-
我没有使用任何占位符。标签显示如上图
标签: javascript jquery html css