javascript 是否可以在 html 的文本字段中显示图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10695544/
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
Is it possible to display an image in text field in html?
提问by Adham
Can we display image inside a text field in html
?
我们可以在文本字段中显示图像html
吗?
Edit
编辑
What I want to do is to have an editable
area, and want to add html
objects inside it(i.e. button, image ..etc)
我想要做的是有一个editable
区域,并想在其中添加html
对象(即按钮、图像等)
回答by Oscar Jara
Image in text field:
文本字段中的图像:
You can do it with CSS.
你可以用 CSS 做到这一点。
Look this example:
看这个例子:
http://jsfiddle.net/oscarj24/zy7YP/1/
http://jsfiddle.net/oscarj24/zy7YP/1/
CSS:
CSS:
.icon {
background:#FFFFFF url(http://icons.iconarchive.com/icons/gakuseisean/ivista-2/16/Start-Menu-Search-icon.png) no-repeat 4px 4px;
padding:4px 4px 4px 22px;
height:18px;
}?
HTML:
HTML:
<input type="text" name="sample" class="icon">?
According to your post edit, maybe this helps.
根据您的帖子编辑,也许这会有所帮助。
Editable area with objects inside:
内部有对象的可编辑区域:
回答by prabhatjn
If you want it using HTML I guess the better way would be to keep the image next to the form element and then using css position:relative property place it inside the text field. Not elegant but works in most cases.
如果你想使用 HTML,我想更好的方法是将图像放在表单元素旁边,然后使用 css position:relative 属性将它放在文本字段中。不优雅,但在大多数情况下都有效。