Java Web開發之Servlet獲取ckeditor內容
阿新 • • 發佈:2019-01-24
js:
<!-- ckeditor外掛 --> <script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
window.onload = function(){ //將textarea替換ckeditor var yjfx = null;//研究方向 var jj = null;//簡介 jj = CKEDITOR.replace('jj'); yjfx = CKEDITOR.replace('yjfx'); //''內為textarea元素的name屬性值,而非id屬性值//給ckeditor賦值 var tyjfxcontent = $('#yjfxhd').val(); var jjcontent = $('#jjhd').val(); CKEDITOR.instances.yjfx.setData(tyjfxcontent); CKEDITOR.instances.jj.setData(jjcontent); }
hmtl:
<div class="form-group"> <label>研究方向</label> <textarea value="" name="yjfx" rows="5" class="form-control"></textarea> <input id="yjfxhd" value="${basicInformation.research }" type="hidden"/> </div> <div class="form-group"> <label>簡介</label> <textarea value="" name="jj" rows="5" class="form-control"></textarea> <input id="jjhd" value="${basicInformation.info }" type="hidden"/> </div>
servlet:
//獲得研究方向 String yjfx = request.getParameter("yjfx").toString();//注意""內是textarea的name