【发布时间】:2020-10-01 15:21:31
【问题描述】:
我需要当用户删除(span id“ps”)的内容时,显示span id“lbps”。我需要这样做来替代使用 javascript 的输入占位符。
<style>
[contenteditable="true"].single-line {
white-space: nowrap;
width:200px;
overflow: hidden;
}
[contenteditable="true"].single-line br {
display:none;
}
[contenteditable="true"].single-line * {
display:inline;
white-space:nowrap;
}
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
<body onload="document.getElementById('ps').focus();document.getElementById('ps').click()">
<span id="ps" onkeypress="document.getElementById('lbps').style.visibility='hidden'" contentEditable="true" class="single-line" spellcheck="false" style="position:absolute;border:1px solid grey;display:inline-block;width:140;height:23;padding-top:4px;padding-left:12px"></span>
<div id="lbps" class="noselect" style="cursor:text;position:relative;padding-top:5px;padding-left:16px;color:lightgrey" spellcheck="false" onclick="document.getElementById('ps').focus();document.getElementById('ps').click()">
Contraseña
</div>
</body>
【问题讨论】:
-
什么文本区域?显示所有代码
-
嗨,你可以检查更新我的问题。
-
嗨,你的代码一团糟。你能用图纸或图片来展示你想要做什么吗?
-
你有 onclick="document.getElementById('itext').focus()"> 密码 但你的代码中没有这样的id
-
大多数浏览器都无法在
contenteditables 上触发.focus()。
标签: javascript html contenteditable placeholder