SinaEditor使用方法詳解

來源:互聯網
上載者:User

1.下載SinaEditor

2.JSP調用頁面
複製代碼 代碼如下:
<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>

其中,src="<%=request.getContextPath() %>/edit/editor.htm表示下載的SinaEditor中的editor.htm檔案路徑;帶綠色的兩處ID須一致

3.下載的editor下包含有img.htm和attach.htm,其中第一個為上傳圖片的,第二個是上傳附件的,當然兩個是一樣的使用方法,都可看做上傳檔案的。

4.下面是img.htm中上傳圖片的一個樣本。做記載方便下次使用。
複製代碼 代碼如下:
function chk_imgpath () {
    if($('radio1').checked==true){
   if($("imgpath").value == "http://" || $("imgpath").value == "") {
    window.close();
    return;
   }
   LoadIMG($("imgpath").value);
    }else{
       if($("file1").value == "") {
       alert("請選擇上傳圖片檔案!");
       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('只允許上傳.gif.jpg.png.jpge 類型檔案!');
         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('檔案上傳失敗');
             }
           });
    }
  }

5.後台代碼編寫(不做敘述)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.