简体   繁体   English

jQuery选择器仅在php循环结果的末尾选择最后一个id

[英]jQuery selector only selects last id at the end of php loop result

Pardon me for asking this question again because previous question not totally solves my problem. 请原谅我再次提出这个问题,因为先前的问题不能完全解决我的问题。 So let's begin. 因此,让我们开始吧。 I am fetching data from database where I use foreach loop to display them. 我正在从数据库中获取数据,并使用foreach循环来显示它们。 It works okay and displays what I wanted but the issue is with 它可以正常工作并显示我想要的,但是问题出在

<div id="uploader<?php echo $value['id']?>">Upload</div> . <div id="uploader<?php echo $value['id']?>">Upload</div>

What I am doing here is concat the id value with id from database and it prints okay like this. 我在这里所做的是将id值与数据库中的id并置,这样就可以正常打印了。

  • uploader1 uploader1
  • uploader2 uploader2
  • uploader3 uploader3

Now I use this jquery code to select all the ids and display each uploader for every loop. 现在,我使用此jquery代码选择所有id,并为每个循环显示每个上载器。

$(document).ready(function($) {
  $("[id*=fileuploader]").uploadFile({
    url:"YOUR_FILE_UPLOAD_URL",
    fileName:"myfile"
  });
});

The code runs with no errors in console but what I found is that it only selects the last result of the loop. 该代码在控制台中运行没有错误,但是我发现它仅选择循环的最后结果。 So the upload button now is only showing on the last result not in all. 因此,上传按钮现在仅显示在最后一个结果上,而不是全部显示。 Can you give me some directions to solve this? 你能给我一些指导来解决这个问题吗? Thanks 谢谢

I think the problem is with your filename: 我认为问题出在您的文件名:

$(document).ready(function($) { 
$("[id*=fileuploader]").each(function(i,v){
  $(v).uploadFile({ url:"YOUR_FILE_UPLOAD_URL", fileName:"myfile"+i })
 });
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM