jQuery如何在单击其他范围时获得跨度值

时间:2021-10-05 20:33:35

I am trying to get the fileid and filename L98BIv2_inv_12.txt when a user clicks on plupload_delete class

当用户点击plupload_delete类时,我试图获取fileid和文件名L98BIv2_inv_12.txt

<<span id="fileId-1">
<a style="clear:left" class="item ui-corner-all" href="#" title="">
    <span id="fileId-1" class="ui-icon ui-icon-close plupload_delete"></span>
    <span class="value plupload_file_name">L98BIv2_inv_11.txt</span>
</a>
<a class="item ui-corner-all" href="#">
    <span class="value noicon plupload_file_size">1 KB</span>
</a>
<a class="item progress ui-corner-all" href="#" style="display:none">
    <span class="value noicon plupload_file_status">Uploading ...</span>
</a>

<span id="fileId-2">
<a style="clear:left" class="item ui-corner-all" href="#" title="">
    <span id="fileId-2" class="ui-icon ui-icon-close plupload_delete"></span>
    <span class="value plupload_file_name">L98BIv2_inv_12.txt</span>
</a>
<a class="item ui-corner-all" href="#">
    <span class="value noicon plupload_file_size">2 KB</span>
</a>
<a class="item progress ui-corner-all" href="#" style="display:none">
    <span class="value noicon plupload_file_status">Uploading ...</span>
</a>

Below is my jQuery function

下面是我的jQuery函数

$('.plupload_delete', target).click(function(e) {
     var fid = $(this).attr("id")
     fid = fid.replace("fileId-",""); 
});

I am able to get the fileId but I couldnt get the filename L98BIv2_inv_12.txt from span class value plupload_file_name

我能够获取fileId但我无法从span类值plupload_file_name获取文件名L98BIv2_inv_12.txt

can someone help me with this?

有人可以帮我弄这个吗?

1 个解决方案

#1


All you need is $(this).text():

你需要的只是$(this).text():

 $('.plupload_delete', target).click(function(e) {
      var fid = $(this).attr("id")
      fid = fid.replace("fileId-",""); 

      var name = $(this).next().text();
 });

Please note that you need .next() because the span containing the file name is just after the clicked span.

请注意,您需要.next(),因为包含文件名的范围恰好在单击的范围之后。

#1


All you need is $(this).text():

你需要的只是$(this).text():

 $('.plupload_delete', target).click(function(e) {
      var fid = $(this).attr("id")
      fid = fid.replace("fileId-",""); 

      var name = $(this).next().text();
 });

Please note that you need .next() because the span containing the file name is just after the clicked span.

请注意,您需要.next(),因为包含文件名的范围恰好在单击的范围之后。