Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像上传器。JQuery_Jquery_Html_Asp.net - Fatal编程技术网

图像上传器。JQuery

图像上传器。JQuery,jquery,html,asp.net,Jquery,Html,Asp.net,我的任务有些问题。我创建了asp.NETMVC项目并将图像上传到服务器。对于上传,我使用swfupload。有创建上传程序的代码: <script> $(function() { $("#photo").makeAsyncUploader({ upload_url: "/Home/AsyncUpload/<%= ViewData["guid"]%>", flash_url: '/Scripts/swfupload.swf',

我的任务有些问题。我创建了asp.NETMVC项目并将图像上传到服务器。对于上传,我使用swfupload。有创建上传程序的代码:

<script>
  $(function() {
    $("#photo").makeAsyncUploader({
      upload_url: "/Home/AsyncUpload/<%= ViewData["guid"]%>",
      flash_url: '/Scripts/swfupload.swf',
      button_image_url: '/Content/blankButton.png',
      disableDuringUpload: 'INPUT[type="submit"]'
    });
  });
</script> 

$(函数(){
$(“#照片”).makeAsyncUploader({
上传url:“/Home/AsyncUpload/”,
flash_url:“/Scripts/swfupload.swf”,
按钮\图像\ url:'/Content/blankButton.png',
加载时禁用:“输入[type=“submit”]”
});
});
这是一个名为“照片”的按钮。但必须有更多名为“photo1”“photo2”的按钮。。。我为添加到div新输入创建了脚本:

<input type="button" onclick="add()" value="Add new button"/>
<script type="text/javascript">
  function add() {
    var newelement = document.createElement('p');
    newelement.setAttribute("class", "file_input");
    var x = ((document.getElementById('uploadImage').getElementsByTagName('p').length));
    var fileinput = document.createElement('input');
    fileinput.setAttribute("name", "photo" + x);
    fileinput.setAttribute("type", "file");
    newelement.appendChild(fileinput);
    document.getElementById('uploadImage').appendChild(new_element);
  }
</script>

函数add(){
var newelement=document.createElement('p');
setAttribute(“类”、“文件输入”);
var x=((document.getElementById('uploadImage').getElementsByTagName('p').length));
var fileinput=document.createElement('input');
setAttribute(“名称”、“照片”+x);
setAttribute(“类型”、“文件”);
newelement.appendChild(fileinput);
document.getElementById('uploadImage').appendChild(新的_元素);
}
它正在工作。它将添加按钮添加到我的div

<div id="uploadImage">
  <p>Photo: <input type="file" id="photo" name="photo"/> </p>                                                                              
</div>

照片:


我有一个问题,当我添加一个新按钮时,它将加载的脚本应该是什么。感谢并为我的英语感到抱歉。

如果我正确理解了您的问题,您的add()函数应该如下所示:

<script>
var uploadButtonCount = 0;
function add() {
   var uploadButtonId = "photo" + uploadButtonCount++;
   var uploadInput = $('<input id="' + uploadButtonId + '" type="file" name="photo"/>');
   $("#uploadImage").append(uploadInput);

   uploadInput.makeAsyncUploader({
         upload_url: "/Home/AsyncUpload/<%= ViewData["guid"]%>",
         flash_url: '/Scripts/swfupload.swf',
         button_image_url: '/Content/blankButton.png',
         disableDuringUpload: 'INPUT[type="submit"]'
   });
}
</script> 

var uploadButtonCount=0;
函数add(){
var uploadButtonId=“photo”+uploadButtonCount++;
var uploadInput=$('');
$(“#uploadImage”).append(uploadInput);
uploadInput.makeAsyncUploader({
上传url:“/Home/AsyncUpload/”,
flash_url:“/Scripts/swfupload.swf”,
按钮\图像\ url:'/Content/blankButton.png',
加载时禁用:“输入[type=“submit”]”
});
}

您需要将新创建的具有唯一id的输入传递给插件。

是。非常感谢你。