1. Download SinaEditor
2.JSP call page
Copy the code code as follows:
<textarea name="problemBody" id="content" style="display:none;" textarea>
<iframe src="<%=request.getContextPath() %>/edit/editor.htm?id=content&ReadCookie=0" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No">< /iframe>
Among them, src="<%=request.getContextPath() %>/edit/editor.htm represents the editor.htm file path in the downloaded SinaEditor; the two IDs in green must be consistent
3. The downloaded editor contains img.htm and attach.htm. The first one is for uploading pictures, and the second one is for uploading attachments. Of course, both are used in the same way and can be regarded as uploading files.
4. The following is an example of uploading images in img.htm. Make a note for future use.
Copy the code code as follows:
function chk_imgpath () {
if($('radio1').checked==true){
if($("imgpath").value == "http://" || $("imgpath").value == "") {
window.close();
return;
}
LoadIMG($("imgpath").value);
}else{
if($("file1").value == "") {
alert("Please choose to upload image files!");
return;
}
var filepath = j("#file1").val();
var filetype = filepath.substring(filepath.lastIndexOf('.'));
var regu = ".gif.jpg.png.jpge.GIF.JPG.PNG";
if (regu.indexOf(filetype) == -1) {
alert('Only files of type .gif.jpg.png.jpge are allowed to be uploaded!');
return ;
}
var f = j('#form1');
j.ajaxFileUpload({
type: 'POST',
secureuri : false,
fileElementId : 'file1',
url: '/ask/fileUpload?type=img',
dataType : 'String',
success : function(data){
j("#imgpath").attr("value",data);
j("#radio1").attr("checked","true");
chk_imgpath();
$('divProcessing').style.display='';
},
error : function(data){
alert('File upload failed');
}
});
}
}
5. Backend code writing (no description)