2014-10-10 79 views
0

我有一堆像电子邮件,名称,消息等输入形式。我已经使所有的字段是强制性的。是否有可能与jQuery的预填充信息textarea与其他形式的输入,但用户仍然可以编辑一些文本?我的目标是根据用户的输入+其他一系列信息提供一种div预览。预览的目标是在提交时向用户展示他/她的邮件在电子邮件中的样子。 例以下领域如何根据用户输入和显示预览预先填写一个textarea?

Name: John Doe 
email: [email protected] 
Institution: Institute of Aquaculture 

的,我想用预填信息的textarea:

To Whom It May Concern:  

Please supply document: {Item requested}. Retrieved from 
{Referring Page}. 

I will use the requested material only for private study, scholarship or 
research. 

Regards, 
John Doe<[email protected]> 

用户可以编辑textarea的内容,如果他/她是不是对内容感到满意,并会喜欢添加其他信息。

我想股利预览显示:

**This is the text to be sent to the responsible person.** 

To Whom It May Concern:  

Please supply document: {Item requested}. Retrieved from 
{Referring Page} 

I will use the requested material only for private study, scholarship or 
research. 

Regards, 
John Doe<[email protected]> 

Name: {From input form} 
Institution: {From input form} 
Item requested: {Generated automatically} 
Logged In As: {from input form} 
Referring Page: {Generated automatically} 

请注意,项目要求参考自动生成页面。我在how to pre-fill/populate a textareahow to generate a preview based on input forms的stackoverflow中搜索,但不知怎的,我不知道如何结合这两个。有关如何实现这一目标的任何建议或完全可能?提前致谢。

+0

像这样完整的例子吗? http://jsfiddle.net/qcxmb75z/ – rogelio 2014-10-10 04:20:42

+0

@rogelio,是的,你可以请你发布你的答案,以便我可以接受它吗?我前一段时间只是想到了它,但是你的代码更加清晰。你还可以编辑你的代码,以便它会生成div预览?非常感谢! – euler 2014-10-10 04:33:53

+0

好的,看我的更新:D – rogelio 2014-10-10 05:20:31

回答

1

基本上,为了预先填充textarea,创建一个字符串,然后替换输入中的值。在这个例子中,我2个冒号字之间封闭供以后更换:

var text = "Some text here, this is the :name: from input"; 

text = text.replace(':name:', $('#name').val()); 

查看jsfiddle

+0

只是为了完成我的回答。用'text.replace(/:name:/ g,“the_text”)''你可以替换所有出现的:name:' – rogelio 2014-10-10 15:32:37

相关问题