zoukankan      html  css  js  c++  java
  • 在套用母版页的页面中应用input file上传图片

    在套用母版页的页面中应用input type="file" 上传图片

    若是Request.Files 始终是0,添加以下信息:

    (1)在套用页面Page_Load中添加 Form.Enctype = "multipart/form-data";不要在母版页中加

    (2)确保input type="file"包含 name属性,不然也取不到上传的文件。

    另附一段JS动态添加上传标签的JS代码:

     1 function AddFileControl() {
     2     var uploads = document.getElementsByName("upFile");
     3     if (uploads.length >= 10) {
     4         alert("最多可以添加10个附件");
     5         return false;
     6     }
     7     var innerDiv = document.createElement("div");
     8     document.getElementById("dv1").appendChild(innerDiv);
     9     var fileControl = document.createElement("input");
    10     fileControl.name = "upFile";
    11     fileControl.type = "file";
    12     innerDiv.appendChild(fileControl);
    13     var btnControl = document.createElement("input");
    14     btnControl.name = "btnDelete";
    15     btnControl.type = "button";
    16     btnControl.setAttribute("value", "删除");
    17     btnControl.onclick = function () { DeleteFileControl(this.parentNode) };
    18     innerDiv.appendChild(btnControl);
    19 }
    20 
    21 function DeleteFileControl(obj) {
    22     document.getElementById("dv1").removeChild(obj);
    23 }

    上传标签统一添加到页面名为:dv1的DIV标签中

  • 相关阅读:
    edu_2_4_1
    edu_2_3_2
    edu_2_3_1
    edu_2_2_2
    edu_2_1_1
    edu_2_2_1
    hdu 1270 小希的数表
    hdu 2151 worm
    hdu1089 Ignatius's puzzle
    hdu 2190 悼念512汶川大地震遇难同胞——重建希望小学
  • 原文地址:https://www.cnblogs.com/lyghost/p/2497783.html
Copyright © 2011-2022 走看看