Javascript 如何在 html 表单字段中显示提示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14589807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:18:37  来源:igfitidea点击:

How to display hints in html form fields?

javascripthtmlhint

提问by ayan khan

I have a very long php form which is used to save input values entered by users. I want to show hints next to the input boxes. I know this HTML input field hintbut this is not my goal, i want to show it next to the input boxes which will appear/disappear when ever user selects the respective field. (i want this in html not in javascript etc because i do not know JavaScript.)

我有一个很长的 php 表单,用于保存用户输入的输入值。我想在输入框旁边显示提示。我知道这个HTML 输入字段提示,但这不是我的目标,我想在用户选择相应字段时将出现/消失的输入框旁边显示它。(我想要在 html 中而不是在 javascript 等中,因为我不知道 JavaScript。)

回答by nsthethunderbolt

You should use HTML5 and use textfields like

您应该使用 HTML5 并使用文本字段,例如

<input type="text" placeholder="enter input" title="Enter input here">

回答by Tom Smilack

You can do it with the :focusCSS pseudo-class. Put a span next to the input box and give it this style:

您可以使用:focusCSS 伪类来实现。在输入框旁边放置一个跨度并给它这种样式:

.hint { display: none; }
input:focus + .hint { display: inline; }

JSBin: http://jsbin.com/inilot/1/edit

JSBin:http: //jsbin.com/inilot/1/edit

回答by Aminadav Glickshtein

This is a CSS technique without using any Java{script} code:

这是一种不使用任何 Java{script} 代码的 CSS 技术:

<style>
.ami div {display:none}
.ami:hover div {display:block}
</style>
<a class=ami href="#">Please hover me <div>I show only when you over</div></a>
</html>

Hope I Help

希望我有所帮助

回答by TN888

You can use titleargument like this :

您可以使用这样的title参数:

<input title="hint" ... />

<input title="hint" ... />