uploadbutton.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Upload Button Examples</title>
  6. <link rel="stylesheet" href="../themes/default/default.css" />
  7. <script src="../kindeditor-min.js"></script>
  8. <script>
  9. KindEditor.ready(function(K) {
  10. var uploadbutton = K.uploadbutton({
  11. button : K('#uploadButton')[0],
  12. fieldName : 'imgFile',
  13. url : '../php/upload_json.php?dir=file',
  14. afterUpload : function(data) {
  15. if (data.error === 0) {
  16. var url = K.formatUrl(data.url, 'absolute');
  17. K('#url').val(url);
  18. } else {
  19. alert(data.message);
  20. }
  21. },
  22. afterError : function(str) {
  23. alert('自定义错误信息: ' + str);
  24. }
  25. });
  26. uploadbutton.fileBox.change(function(e) {
  27. uploadbutton.submit();
  28. });
  29. });
  30. </script>
  31. </head>
  32. <body>
  33. <div class="upload">
  34. <input class="ke-input-text" type="text" id="url" value="" readonly="readonly" /> <input type="button" id="uploadButton" value="Upload" />
  35. </div>
  36. </body>
  37. </html>