Hopes

          Start Here..

           

          上傳文件

          Html代碼  收藏代碼
          1. <html>      
          2.      
          3. <head>      
          4.      
          5. <title>Add Files</title>      
          6.      
          7. <style>      
          8.      
          9. a.addfile {      
          10.      
          11. background-image:url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);      
          12.      
          13. background-repeat:no-repeat;      
          14.      
          15. background-position:-823px -17px;      
          16.      
          17. display:block;      
          18.      
          19. float:left;      
          20.      
          21. height:20px;      
          22.      
          23. margin-top:-1px;      
          24.      
          25. position:relative;      
          26.      
          27. text-decoration:none;      
          28.      
          29. top:0pt;      
          30.      
          31. width:80px;      
          32.      
          33. }      
          34.      
          35.      
          36.      
          37. input.addfile {      
          38.      
          39. /*left:-18px;*/     
          40.      
          41. }      
          42.      
          43.      
          44.      
          45. input.addfile {      
          46.      
          47. cursor:pointer !important;      
          48.      
          49. height:18px;      
          50.      
          51. left:-13px;      
          52.      
          53. filter:alpha(opacity=0);      
          54.      
          55. position:absolute;      
          56.      
          57. top:5px;      
          58.      
          59. width:1px;      
          60.      
          61. z-index: -1;      
          62.      
          63. }      
          64.      
          65. </style>      
          66.      
          67.      
          68.      
          69. <script type="text/javascript">      
          70.      
          71.      
          72.      
          73. function MultiSelector(list_target, max)      
          74.      
          75. {      
          76.      
          77.     // Where to write the list      
          78.      
          79.     this.list_target = list_target;      
          80.      
          81.     // How many elements?      
          82.      
          83.     this.count = 0;      
          84.      
          85.     // How many elements?      
          86.      
          87.     this.id = 0;      
          88.      
          89.     // Is there a maximum?      
          90.      
          91.     if (max)      
          92.      
          93.      {      
          94.      
          95.         this.max = max;      
          96.      
          97.      }      
          98.      
          99.     else      
          100.      
          101.      {      
          102.      
          103.         this.max = -1;      
          104.      
          105.      };      
          106.      
          107.      
          108.      
          109.     /**   
          110.   
          111.       * Add a new file input element   
          112.   
          113.       */     
          114.      
          115.     this.addElement = function(element)      
          116.      
          117.      {      
          118.      
          119.         // Make sure it's a file input element      
          120.      
          121.         if (element.tagName == 'INPUT' && element.type == 'file')      
          122.      
          123.          {      
          124.      
          125.             // Element name -- what number am I?      
          126.      
          127.              element.name = 'file_' + this.id++;      
          128.      
          129.      
          130.      
          131.             // Add reference to this object      
          132.      
          133.              element.multi_selector = this;      
          134.      
          135.      
          136.      
          137.             // What to do when a file is selected      
          138.      
          139.              element.onchange = function()      
          140.      
          141.              {      
          142.      
          143.                 // New file input      
          144.      
          145.                 var new_element = document.createElement('input');      
          146.      
          147.                  new_element.type = 'file';      
          148.      
          149.                  new_element.size = 1;      
          150.      
          151.                  new_element.className = "addfile";      
          152.      
          153.      
          154.      
          155.                 // Add new element      
          156.      
          157.                 this.parentNode.insertBefore(new_element, this);      
          158.      
          159.      
          160.      
          161.                 // Apply 'update' to element      
          162.      
          163.                 this.multi_selector.addElement(new_element);      
          164.      
          165.      
          166.      
          167.                 // Update list      
          168.      
          169.                 this.multi_selector.addListRow(this);      
          170.      
          171.      
          172.      
          173.                 // Hide this: we can't use display:none because Safari doesn't like it      
          174.      
          175.                 this.style.position = 'absolute';      
          176.      
          177.                 this.style.left = '-1000px';      
          178.      
          179.              };      
          180.      
          181.      
          182.      
          183.      
          184.      
          185.             // If we've reached maximum number, disable input element      
          186.      
          187.             if (this.max != -1 && this.count >= this.max)      
          188.      
          189.              {      
          190.      
          191.                  element.disabled = true;      
          192.      
          193.              };      
          194.      
          195.      
          196.      
          197.             // File element counter      
          198.      
          199.             this.count++;      
          200.      
          201.             // Most recent element      
          202.      
          203.             this.current_element = element;      
          204.      
          205.          }      
          206.      
          207.         else      
          208.      
          209.          {      
          210.      
          211.             // This can only be applied to file input elements!      
          212.      
          213.              alert('Error: not a file input element');      
          214.      
          215.          };      
          216.      
          217.      };      
          218.      
          219.      
          220.      
          221.      
          222.      
          223.     /**   
          224.   
          225.       * Add a new row to the list of files   
          226.   
          227.       */     
          228.      
          229.     this.addListRow = function(element)      
          230.      
          231.      {      
          232.      
          233.         // Row div      
          234.      
          235.         var new_row = document.createElement('div');      
          236.      
          237.      
          238.      
          239.         // Delete button      
          240.      
          241.         var new_row_button = document.createElement('input');      
          242.      
          243.          new_row_button.type = 'button';      
          244.      
          245.          new_row_button.value = 'Delete';      
          246.      
          247.      
          248.      
          249.         // References      
          250.      
          251.          new_row.element = element;      
          252.      
          253.      
          254.      
          255.         // Delete function      
          256.      
          257.          new_row_button.onclick = function()      
          258.      
          259.          {      
          260.      
          261.             // Remove element from form      
          262.      
          263.             this.parentNode.element.parentNode.removeChild(this.parentNode.element);      
          264.      
          265.      
          266.      
          267.             // Remove this row from the list      
          268.      
          269.             this.parentNode.parentNode.removeChild(this.parentNode);      
          270.      
          271.      
          272.      
          273.             // Decrement counter      
          274.      
          275.             this.parentNode.element.multi_selector.count--;      
          276.      
          277.      
          278.      
          279.             // Re-enable input element (if it's disabled)      
          280.      
          281.             this.parentNode.element.multi_selector.current_element.disabled = false;      
          282.      
          283.      
          284.      
          285.             // Appease Safari      
          286.      
          287.             // without it Safari wants to reload the browser window      
          288.      
          289.             // which nixes your already queued uploads      
          290.      
          291.             return false;      
          292.      
          293.          };      
          294.      
          295.      
          296.      
          297.         // Set row value      
          298.      
          299.          new_row.innerHTML = element.value + " ";      
          300.      
          301.      
          302.      
          303.         // Add button      
          304.      
          305.          new_row.appendChild(new_row_button);      
          306.      
          307.      
          308.      
          309.         // Add it to the list      
          310.      
          311.         this.list_target.appendChild(new_row);      
          312.      
          313.      };      
          314.      
          315. };      
          316.      
          317. </script>      
          318.      
          319. </head>      
          320.      
          321.      
          322.      
          323. <body>      
          324.      
          325.      
          326.      
          327. <!-- This is the form -->      
          328.      
          329. <form enctype="multipart/form-data" action="http://127.0.0.1:8080/xxx/fileUploadAction.action" method="post">      
          330.      
          331. <!-- The file element -- NOTE: it has an ID -->      
          332.      
          333. <a href="javascript:void(1==1);" class="addfile" style="cursor: default;" hidefocus="true">      
          334.      
          335. <input id="my_file_element" class="addfile" type="file" name="file_1" size="1" title="點擊選擇附件">      
          336.      
          337. </a>      
          338.      
          339. <input type="submit" value="上 傳">      
          340.      
          341. </form>      
          342.      
          343.      
          344.      
          345. Files:      
          346.      
          347. <!-- This is where the output will appear -->      
          348.      
          349. <div id="files_list" style="padding:5px;border:1px;border-style:solid;border-color:#0000ff;height:100px;width:600px;"></div>      
          350.      
          351. <script>      
          352.      
          353. <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->      
          354.      
          355. var multi_selector = new MultiSelector(document.getElementById('files_list'), 100);      
          356.      
          357. <!-- Pass in the file element -->      
          358.      
          359. multi_selector.addElement(document.getElementById('my_file_element'));      
          360.      
          361. </script>      
          362.      
          363.      
          364.      
          365. </body>      
          366.      
          367. </html>     












          美化上傳控件的辦法;

          2007-04-27 16:39 by 迷路中的路人甲, 364 閱讀, 0 評論, 收藏編輯
          還有一個問題就是,如何利用這一個控件,進行多個文檔的上傳工作?
              利用dom操作,當每次選擇了一個文件的時候,隱藏該file域,在相同位置創建一個新的供下次點擊,刪除的時候只要直接刪掉隱藏的就行了[初步想法未經證實]
          一直以來上傳控件input file都無法進行美化,例如換個圖片什么的;查了很多資料最終就是需要利用隱藏file域實現上傳功能;其實很簡單,從163里面找了一個樣式出來,搞定;

          js代碼: //依賴prototype.js
          function selfile()
          {
            $(
          "fileurl").value = $("file").value;
          }   

          css代碼://來自mail.163.com
          a.addfile{width:70px;height:20px;position:relative;cursor:hand;top:4px;top/**/:0;text-decoration:none;background-position:-823px -17px;display:inline;float:left;margin-top:-5px;margin-top/**/:-1px}
          *:lang(zh) a.addfile
          {margin-top:-2px;cursor:pointer}
          a.addfile:hover
          {background-position:-911px -17px;text-decoration:none}
          input.addfile
          {width:1px;height:18px;cursor:pointer!important;cursor:hand;position:absolute;top:5px;left:-5px;left/**/:-3px;opacity:0;filter:alpha(opacity=0)}
          *:lang(zh) input.addfile
          {left:-18px}

          html代碼://
          <input type="text" value="" id="fileurl" name="fileurl" readonly/>
          <a  href="#" class="addfile"> <input type="file" name="file" id="file" hideFocus class="addfile" onChange="selfile();"/>+添加附件(也可以放個美化的圖片) </a>
















          posted on 2012-07-19 11:06 ** 閱讀(166) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宽甸| 象州县| 观塘区| 英吉沙县| 古交市| 牟定县| 乌鲁木齐市| 海安县| 昌吉市| 自贡市| 呼图壁县| 嘉黎县| 江口县| 突泉县| 济宁市| 马公市| 神农架林区| 响水县| 敖汉旗| 渭源县| 石棉县| 竹山县| 安仁县| 凌云县| 沧源| 栾川县| 白城市| 吴忠市| 十堰市| 泰州市| 柳林县| 邻水| 宣化县| 渝中区| 南木林县| 云梦县| 武宣县| 攀枝花市| 景洪市| 新兴县| 荔波县|