简体   繁体   English

如何在textarea中呈现HTML模板?

[英]How to render HTML template in textarea?

I have a textarea and a resume/CV sample template on document. 我在文档上有一个textarea和一个简历/ CV示例模板。

On button event that template's HTML is the value of textarea. 在按钮事件上,模板的HTML是textarea的值。

I am doing it as below- 我这样做如下 -

$(function(){
    $('#select-sample').click(function(){
    var sample=$('.ok').html();
        $('.summernote').val(sample);
    });

});

This is just a simple copy thing is happening in textarea, I am picking up an HTML of template and copying it into textarea. 这只是一个简单的复制事情发生在textarea,我正在拿起一个模板的HTML并将其复制到textarea。

My question- 我的问题-

How do I render that HTML template in textarea as it is rendered in document. 如何在textarea中呈现该HTML模板,因为它在文档中呈现。 I don't want rendered HTML. 我不想渲染HTML。

Why won't Textarea render this HTML template when all related css classes are attached within document itself? 当所有相关的css类都附加在文档本身中时,为什么Textarea不会呈现此HTML模板?

Fiddle for this 小提琴这个

Textarea elements are intended only for text input or manipulation, they have nothing to do with rendering. Textarea元素仅用于文本输入或操作,它们与渲染无关。 If you want to render, make a div: <div class="summernote"></div> . 如果你想渲染,请创建一个div: <div class="summernote"></div> And change your jQuery to: $('.summernote').html(sample); 并将您的jQuery更改为: $('.summernote').html(sample);

这是因为textarea元素只显示文本,如果你想使用标记你将需要使用javascript和contenteditable属性或包含一个wysiwyg编辑器脚本,其中许多可以很容易找到,虽然其中一个最知名编辑将是tinyMCE

You can use $('.summernote').code(sHTML); 你可以使用$('.summernote').code(sHTML);

http://hackerwins.github.io/summernote/features.html#api-code http://hackerwins.github.io/summernote/features.html#api-code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM