HTML 输入 - 已填充文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30516391/
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-29 11:32:56  来源:igfitidea点击:

HTML Input - already filled in text

htmlinputplaceholder

提问by JavaStudent123

I was wondering, is there a way to put text into an input field? What i've got now is a placeholder, but that's actually an empty inputfield. So that's not what i'm looking for. I'm looking for an (kind of) placeholder that's actually filled in into the input field, so not "background text"

我想知道,有没有办法将文本放入输入字段?我现在得到的是一个占位符,但这实际上是一个空的输入字段。所以这不是我要找的。我正在寻找一个(某种)占位符,它实际上填充到输入字段中,所以不是“背景文本”

This is with placeholder:

这是占位符:

http://i.stack.imgur.com/NWY3y.png

http://i.stack.imgur.com/NWY3y.png

And this is what i want:

这就是我想要的:

http://i.stack.imgur.com/AfGSy.png

http://i.stack.imgur.com/AfGSy.png

Is there any way to do this?

有没有办法做到这一点?

Thanks in advance!

提前致谢!

回答by

The value content attribute gives the default value of the input element.

- http://www.w3.org/TR/html5/forms.html#attr-input-value

value content 属性给出了输入元素的默认值。

- http://www.w3.org/TR/html5/forms.html#attr-input-value

To set the default value of an input element, use the valueattribute.

要设置输入元素的默认值,请使用该value属性。

<input type="text" value="default value">

回答by Matthias

You seem to look for the input attribute value, "the initial value of the control"?

你好像在找输入属性value,“控件的初始值”?

<input type="text" value="Morlodenhof 7" />

https://developer.mozilla.org/de/docs/Web/HTML/Element/Input#attr-value

https://developer.mozilla.org/de/docs/Web/HTML/Element/Input#attr-value

回答by Ryan Bobrowski

All you have to do is use the value attribute of input tags:

您所要做的就是使用输入标签的 value 属性:

<input type="text" value="Your Value" />

Or, in the case of a textarea:

或者,在 textarea 的情况下:

<textarea>Your Value</textarea>

回答by Manoj Kumar

<input type="text" value="Your value">

Use the valueattribute for the pre filled in values.

value属性用于预先填充的值。

回答by Navdeep Kapil

TO give the prefill value in HTML Side as below:

在 HTML Side 中给出 prefill 值,如下所示:

HTML:

HTML:

<input type="text" id="abc" value="any value">

JQUERY:

查询:

$(document).ready(function ()
 {
  $("#abc").val('any value');
 });