1. Download SinaEditor
2. JSP call page
Copy codeThe Code is 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 "width =" 621 "height =" 457 "> </iframe>
The path of the editor.htm file in sinaeditordownloaded by src = "<% = request. getContextPath () %>/edit/editor.htm.pdf; the two IDs with green must be consistent
3.The downloaded editorpackage contains img.htmand attach.htm. The first one is for uploading images, and the second is for uploading attachments. Of course, the two are the same method of use and can be viewed as uploading files.
4.The following is an example of uploading images in img.htm. Make records to facilitate next use.
Copy codeThe Code is 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 ("select to upload an image file! ");
Return;
}
Var filepath = j ("# file1"). val ();
Var filetype = filepath. substring (filepath. lastIndexOf ('.'));
Var regu = ".gif.jpg.png.jpg e. GIF. JPG. PNG ";
If (regu. indexOf (filetype) =-1 ){
Alert('only upload .gif.jpg.png.jpg e files allowed! ');
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 ();
$ ('Didprocessing'). style. display = '';
},
Error: function (data ){
Alert ('file upload failed ');
}
});
}
}
5. Write background Code (not described)