我的任务有些问题。我创建了asp.net mvc项目并将图像上传到服务器。对于上传,我使用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>
这是一个名为“photo”的按钮。但必须有更多名称为“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>
它正在发挥作用。并为我的div添加按钮
<div id="uploadImage">
<p>Photo: <input type="file" id="photo" name="photo"/> </p>
</div>
我有疑问,什么应该是一个脚本,当我添加一个新按钮时,它将swfupload。谢谢,抱歉我的英文。
答案 0 :(得分:0)
如果我理解你的问题,你的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>
您需要将具有唯一ID的新创建的输入传递给插件。