0

我有一个适用于 html5 文件 api 的上传脚本,我想为互联网“代码浪费”资源管理器编写一个后端 iframe 解决方案

所以我有一个通过 iframe 加载的表单,当提交表单时,我将加载模板添加到父文档

这是我的html代码

<form enctype="multipart/form-data" method="post" action="<?php echo $action; ?>" >
<input type="file" name="files[]"  id="files" multiple> 
<input name="profile_id" type="hidden" value="<?php echo $profile_id; ?>">
<input name="" type="button" value="Button" onClick="add_loder();">
</form>

这是我的 add_loder 函数

<script>
var d = $(window.frameElement).parent(); 

function add_loder()
{
    if($('#files').val().length == 0 )
    return false;


    var template = '<div class="preview">'+
                        '<span class="imageHolder">'+
                            '<img class="prv" src="<?php echo IMAGE_URL; ?>done.png" />'+
                            '<span class="uploaded"></span>'+
                        '</span>'+
                        '<div  class="ph" >'+
                            '<img src="<?php echo IMAGE_URL; ?>load_square.gif" style="margin-right:45%;width:27px;height:27px">'+
                        '</div><div class="area"><textarea  class="picarea"> </textarea><input type="button" value="<?php echo $confirmLable; ?>" class="conf">'+
                        '<input  type="button" value="<?php echo $deleteLable; ?>" class="del"><input class="id" type="hidden" value="0"></div>'+
                    '</div>'; 

    d.append(template);
    $('form').submit();

}
</script>

但这只会向页面添加一次加载

我想为每个选定的文件添加一个加载,所以我必须知道选择了多少个文件

4

1 回答 1

2

$('#files')[0].files它是所选文件的集合,因此请尝试$('#files')[0].files.length

于 2012-08-20T05:02:04.217 回答