HTML中的输入字段值 [英] HTML in the input field value

查看:108
本文介绍了HTML中的输入字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让HTML在输入字段的值中工作?如果您在该值中包含HTML,它将显示为纯文本。有没有办法做这样的事情?

 < input type ='text'value ='< b> tekst< ; / b个'>< /输入> 

所以输出结果是:

tekst



而不是

< b> tekst



我认为这是一个糟糕的例子...我希望每个适当的HTML标签都能正常工作。如果我想包含图片,图片会出现在输入框中,如果我想添加标签...文本应显示为链接链接。

解决方案

我不确定您的问题是否尝试使值包含HTML,或者您是否希望将HTML应用于输入内的某些内容。



如果您希望能够将值设置为某些HTML,例如< input value =< b>某些HTML< / b>>< / code>其中的值实际上会显示HTML,您需要对HTML括号进行编码,例如< input value =& lt; b& gt;一些文本< b /& gt ;> 。有些函数可以在大多数脚本语言中自动执行此操作(例如PHP中的htmlentities())。

如果要将HTML应用于输入值,答案是......你不能。如果你想在那里格式化,你可以使用HTML5中的contentEditable属性,它可以让你就地编辑(想象Flickr标题)。



如果你只想要一个标准输入字段的样式,您可以像使用其他答案一样使用CSS。


How can I get HTML to work in the value of the input field ? If you include HTML in the value, it appears as pure text. Is there a way to do something like this?

<input type='text' value='<b>tekst</b>'></input>

So the the output is:

tekst

instead of

<b>tekst</b>

I think that was bad example... I want every appropriate HTML tag to work. If i want to include an image, the image appears in the input, if i want to add a tag ... the text should appear as a link linked.

解决方案

I'm not sure from your question whether you are trying to make the value contain HTML, or whether you want to apply HTML to something inside the input.

If you want to be able to set the value to some HTML, like <input value="<b>Some HTML</b>"> where the value will actually show the HTML, you need to encode the HTML brackets like <input value="&lt;b&gt;Some text&lt;b/&gt;">. There are functions available to do this for you automatically in most scripting languages (e.g. htmlentities() in PHP).

If you want to apply HTML to the input value, short answer is... you can't. If you want formatting on there, you could use the contentEditable attribute in HTML5 which lets you just edit-in-place (think Flickr headers).

If you just want a standard input field to be styled, you can just use CSS like the other answers suggested.

这篇关于HTML中的输入字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆