你的位置: 首页>> JS&CSS, 技术天空 >> Discuz!多附件上传选择框之jQuery版

Discuz!多附件上传选择框之jQuery版

热度:



看Discuz!附件上传时候的选择框做的很不错
就拿jQuery练手顺手写了一个
jQuery多附件上传的演示效果就如Discuz!的上传选择框是一样的,不同的只是代码,现在拿出来给大家分享一下。:)

代码如下:

  1. var aid = 1;
  2. var attachexts = new Array();
  3. var attachwh = new Array();
  4. function addAttach() {
  5. newnode = $(”#attachbodyhidden > tr”).clone();
  6. var id = aid;
  7. var tags;
  8. tags = newnode.find(”input”);
  9. for(i in tags) {
  10. if(tags[i].name == ‘attach[]‘) {
  11. tags[i].id = ‘attach_’ + id;
  12. tags[i].onchange = function() {insertAttach(id)};
  13. tags[i].unselectable = ‘on’;
  14. }
  15. if(tags[i].name == ‘localid[]‘) {
  16. tags[i].value = id;
  17. }
  18. }
  19. tags = newnode.find(”span”);
  20. for(i in tags) {
  21. if(tags[i].id == ‘localfile[]‘) {
  22. tags[i].id = ‘localfile_’ + id;
  23. }
  24. }
  25. aid++;
  26. $(”#attachbody”).append(newnode);
  27. }
  28. function insertAttach(id) {
  29. var localimgpreview = ”;
  30. var path = $(”#attach_” + id).attr(”value”);
  31. var ext = path.lastIndexOf(’.') == -1 ? ” : path.substr(path.lastIndexOf(’.') + 1, path.length).toLowerCase();
  32. var re = new RegExp(”(^|\\s|,)” + ext + “($|\\s|,)”, “ig”);
  33. var localfile = $(”#attach_” + id).attr(”value”).substr($(”#attach_” + id).attr(”value”).replace(/\\/g, ‘/’).lastIndexOf(’/') + 1);
  34. attachexts[id] = in_array(ext, ['gif', 'jpg', 'png', 'bmp']) ? 2 : 1;
  35. $(”#localfile_” + id).html(’<a href=”###delAttach” onclick=”delAttach(’ + id + ‘)”>[' + lang['post_attachment_deletelink'] + ‘]</a> <a href=”###insertAttach” title=”‘ + lang['post_attachment_insert'] + ‘” onclick=”insertAttachtext(’ + id + ‘, ‘ + attachexts[id] + ‘);return false;”>[' + lang['post_attachment_insertlink'] + ‘]</a> <span id=”localimgpreview_’ + id + ‘” > </span><span class=”smalltxt”>[' +id + ']</span> ‘ + localfile + ”);
  36. $(”#attach_” + id).css(”display”,’none’);//style.display = ‘none’;
  37. addAttach();
  38. }
  39. function delAttach(id) {
  40. $(”#attach_” + id).parent().parent().remove();
  41. $(”#attachbody”).html() == ” && addAttach();
  42. }
  43. $(document).ready(function() {
  44. addAttach();
  45. });


Tags:

留个脚印

Copyright © 2010 高度PHP All rights reserved.
Designed by Modified by ifanqie. Powered by WordPress.