add html content to hidden form field

五迷三道 提交于 2019-12-11 07:04:54

问题


Is it possible to pass a chunk of html content to a hidden field and how would I do this?

Thanks

Jonathan


回答1:


Yes - simply HTML encode the content (e.g. replace "<" with "&lt" etc...)

You didn't specify which language you'll use for poplulating the field value, so I can't help with details of how to encode.

Here's a reference of how to do it in jQuery.

Here's Java




回答2:


You could do this with Javascript:

<input type="hidden" id="htmlCodes" />
document.getElementById("htmlCodes").value = "<strong>Hello World</strong>";

Just be sure that your values are properly-escaped when you pass them into the hidden form field.

Online Demo: http://jsbin.com/ubofu/edit




回答3:


You can also "spawn" a hidden textarea after processing the content inside.

This can be done easily with Jquery :

$('#your_form')
.append('<textarea name="content" class="hidden">' + your_content + '</textarea>');

Here we assuming that you've got a "hidden" class, Bootstrap's got one, but you can also use this :

CSS Code :

.hidden 
{ 
  display: none !important ; 
  visibility: hidden !important; 
}


来源:https://stackoverflow.com/questions/2364612/add-html-content-to-hidden-form-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!