将html标签转换为字符串

时间:2014-10-10 13:23:19

标签: javascript jquery html

我的ajax调用返回一个字符串,其中我的第一个字符串将是这样的代码

 response[0]=2 

 response[1]= Enter the reasons the application is being returned,<br><br><span style="color: red; font-weight: bold;">* Caution! The text of this Message will be included in notices sent to the applicant *</span>

我正在将此分配给我的输入标签的id,如此

document.getElementById('messageHint').value = response[1] ;

但它并没有将这些<br><span>标记呈现给Html,而只是以相同的格式显示它们。我如何解决此问题。

我尝试了不同的应用,例如parse.Html()$html.prop('outerHTML');,但没有人向我展示所需的输出。

2 个答案:

答案 0 :(得分:1)

我认为您需要使用document.getElementById('messageHint').innerHTML

LIVE DEMO

答案 1 :(得分:0)

 You can give only one style to one placeholder like this:

 <style>

 input::-webkit-input-placeholder { font-size: 16pt; color: #555; }
 input::-moz-placeholder { font-size: 16pt; color: #555; }
 input:-ms-input-placeholder { font-size: 16pt; color: #555; }
 input:-moz-placeholder { font-size: 16pt; color: #555; }  

 input.other::-webkit-input-placeholder { font-size: 12pt; color: red; }
 input.other::-moz-placeholder { font-size: 12pt; color: red; }
 input.other:-ms-input-placeholder { font-size: 12pt; color: red; }
 input.other:-moz-placeholder { font-size: 12pt; color: red; }

 </style>

 <input type="text" placeholder="Hello"></input>
 <input type="text" class="other" placeholder="Hello"></input>

 and yes, .innerhtml is used to put the content into a div, not into an input field. so that's not useful to you in anyway.