我没有导入相应的包javascript
这个用的仍是有些问题css
并且显示的时候格式问题还没解决html
<div class="blog_editor" style="margin: 0 auto;width:60%;height:1000px;background-color: white;">java
<div style="text-align: left"><br>文章标题:<br> <input type="text" id="title" name="title" placeholder="标题不要超过100字" style="width: 100%;margin: 5px 0;height:30px;"/> </div> <div id="test-editormd"> <textarea id="editor-md-doc" name="editor-md-doc" style="display:none;"></textarea> <textarea id="editor-md-html" name="editor-md-html"></textarea> </div> <input name="my_submit" id="my_submit" value="提交" type="button"/> </div>
<script> $("#my_submit").click(function () { alert("正在提交"); submit_atricle(); }) function submit_atricle() { var title = $("#title").val(); var htmlContent = $("#editor-md-html").val(); htmlContent = htmlContent.replace(/\n|\r\n/g,"<br>"); var markdownContent = $("#editor-md-doc").val(); var title=$("#title").val(); $.ajax({ url: "${pageContext.request.contextPath}/article/editorContent.action", data: JSON.stringify({title: title, htmlContent: htmlContent, markdownContent: markdownContent}), type: "POST", contentType: 'application/json', success: function () { alert("发布成功"); }, error: function () { alert("发布失败"); } }) } </script>jquery
//显示的jsajax
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>json
<script src="https://cdn.bootcss.com/showdown/1.3.0/showdown.min.js"></script>markdown
<script type="text/javascript"> var content ='${article.htmlContent}'; //使用el表达式获取后台返回的markdown内容 var converter = new showdown.Converter(); //初始化转换器 var htmlcontent = converter.makeHtml(content); //将MarkDown转为html格式的内容 $("#article").html(htmlcontent);//添加到 div 中 显示出来 </script> app