【问题标题】:Div not applying for all time in the foreach loopDiv 没有在 foreach 循环中一直申请
【发布时间】:2015-01-10 21:09:51
【问题描述】:

这是我上传文件的全部代码

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="https://rawgithub.com/hayageek/jquery-upload-file/master/js/jquery.uploadfile.min.js"></script>
</head>
<body>  
@foreach($value as $val)
<div id="mulitplefileuploader">Upload</div>  // don't confuse with foreach loop it's laravel way
@endforeach  // the loop will run for 5 times (say)
<div id="status"></div>
<script>
$(document).ready(function()
{
var settings = {
    url: "upload.php",
    method: "POST",
    allowedTypes:"jpg,png,gif,doc,pdf,zip",
    fileName: "myfile",
    multiple: true,
    onSuccess:function(files,data,xhr)
    {
        $("#status").html("<font color='green'>Upload is success</font>");
    },
    onError: function(files,status,errMsg)
    {       
        $("#status").html("<font color='red'>Upload is Failed</font>");
    }
}
$("#mulitplefileuploader").uploadFile(settings);

});
</script>

当我尝试在 foreach 循环中使用 &lt;div id="mulitplefileuploader"&gt;Upload&lt;/div&gt; this 时(近 5 次),它只出现在最后一个循环中。

我怎样才能让它出现在所有循环中?

更新:

为了更好地理解,我在这里创建了一个小提琴http://jsfiddle.net/L08p1upt/

我怎样才能在这里有 3 个上传选项?

当我尝试时,我给了我这样的http://jsfiddle.net/L08p1upt/1/

如何同时上传三个文件?

这是我关注的Tutorial

【问题讨论】:

  • 酷,我没有在代码中显示 foreach 循环。但我试过了。让我也用它来更新代码
  • 你的意思是
    Upload
    出现了不止一次?
  • 是的,它应该(我是否应该使用 &lt;div id="mulitplefileuploader1"&gt;&lt;div id="mulitplefileuploader2"&gt; 那样得到还是什么??

标签: php jquery css ajax


【解决方案1】:

感觉应该使用类来查找元素。

试试:

<div id="mulitplefileuploader" class="fileuploader">

$(".fileuploader").uploadFile(settings);

顺便说一句,在多个元素中使用相同的 id 绝不是一个好主意,否则您会经常看到这个问题。正如在 cmets 中所说,您应该枚举 id,即 multiplefileuploader1、multiplefileuploader2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    相关资源
    最近更新 更多