如何在一个页面中使用多个markDown Editor?

时间:2016-04-14 10:43:53

标签: javascript jsp editor markdown

我需要从用户那里获取输入,每次onKeyup()事件都应该预览给用户。

通过外观&感觉和功能它应该像“StackOverFlow”文本输入编辑器一样。

我做了很好的研究。为有其他人分享它。

谢谢&的问候,

Arun Dhwaj

1 个答案:

答案 0 :(得分:1)

查看完整代码:Multiple_Editor_In_One_Page.jsp

步骤1:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>

<html>
<head>
<title>Emotions</title>
<script src="resources/recmJs/Markdown.Converter.js"></script>
<script src="resources/recmJs/Markdown.Editor.js"></script>
<script src="resources/recmJs/check.js"></script>

<link rel="stylesheet" type="text/css" href="resources/recm/feedBack.css">

<script type="text/javascript">

function showPreviewUsingMarkDownEditor( uid )
{
    var converter = new Markdown.Converter();

    var editor = new Markdown.Editor(converter, uid);

    editor.run();
}

</script>

</head>




<body>

<br>
<div id="MarkdownEditor-1"> 

    <p><b>MarkdownEditor-1 in one this page </b></p>

    <div id="write-title" class="wmd-panel">
        <textarea onkeyup="showPreviewUsingMarkDownEditor('-1')" class="wmd-input" id="wmd-input-1" cols="50" rows="6"></textarea>
        <div id="wmd-preview-1" class="wmd-panel wmd-preview"></div>
    </div>
</div>


<br>
<div id="MarkdownEditor-2"> 

    <p><b>MarkdownEditor-2 in one this page </b></p>

    <div id="write-title" class="wmd-panel">
        <textarea onkeyup="showPreviewUsingMarkDownEditor('-2')" class="wmd-input" id="wmd-input-2" cols="50" rows="6"></textarea>
        <div id="wmd-preview-2" class="wmd-panel wmd-preview"></div>
    </div>
</div>




<br>
<div id="MarkdownEditor-3"> 

    <p><b>MarkdownEditor-3 in one this page </b></p>

    <div id="write-title" class="wmd-panel">
        <textarea onkeyup="showPreviewUsingMarkDownEditor('-3')" class="wmd-input" id="wmd-input-3" cols="50" rows="6"></textarea>
        <div id="wmd-preview-3" class="wmd-panel wmd-preview"></div>
    </div>
</div>


<br>
<div id="MarkdownEditor-4"> 

    <p><b>MarkdownEditor-4 in one this page </b></p>

    <div id="write-title" class="wmd-panel">
        <textarea onkeyup="showPreviewUsingMarkDownEditor('-4')" class="wmd-input" id="wmd-input-4" cols="50" rows="6"></textarea>
        <div id="wmd-preview-4" class="wmd-panel wmd-preview"></div>
    </div>
</div>


<br>
<div id="MarkdownEditor-5"> 

    <p><b>MarkdownEditor-5 in one this page </b></p>

    <div id="write-title" class="wmd-panel">
        <textarea onkeyup="showPreviewUsingMarkDownEditor('-5')" class="wmd-input" id="wmd-input-5" cols="50" rows="6"></textarea>
        <div id="wmd-preview-5" class="wmd-panel wmd-preview"></div>
    </div>
</div>


</body>

</html>

步骤2:

Crux部分是:markdown编辑器有三个参数,第一个是强制性的,第二个,第三个是可选的。

在第二个argumnet中,传递了区分后缀id。

如您所知,降价编辑器始终在寻找#wmd-input#wmd-preview元素。

为了在同一页面中区分它,在上面的id中添加后缀,并将该后缀作为第二个参数传递。

多数民众赞成。