如何选择表格行中的图像?

发布于 2024-10-22 18:20:24 字数 3006 浏览 2 评论 0原文

我在页面上有一个表格,如下所示:

<table id="ctl00_PlaceHolderMain_Table_Name" class="schedule-table" cellspacing="1" border="0" style="width:100%;">
<tr>
    <td class="resource-header"><span class="resource-header-text">Personnel</span></td>
    <td class="resource-header"><span class="resource-header-text">Office</span></td>
    <td class="dow"><span class="dow">Tue<br>01</span></td><td class="dow"><span class="dow">Wed<br>02</span></td><td class="dow"><span class="dow">Thu<br>03</span></td><td class="dow"><span class="dow">Fri<br>04</span></td><td class="weekend"><span class="weekend-text">Sat<br>05</span></td><td class="weekend"><span class="weekend-text">Sun<br>06</span></td><td class="dow"><span class="dow">Mon<br>07</span></td>...and so on until end of month...<td class="dow"><span class="dow">Thu<br>31</span></td>
</tr>
<tr class="DataRow" id="DataRow_8">
<td class="resource" style="display:none;"><span class="resource">8</span></td>
<td class="resource" id="TD_Name"><img src="../../images/epas/working.gif" width="16" height="16" alt="Working..." id="imgProgress" /><span title="Lname, Fname " class="resource">Lname, Fname</span></td>
<td class="resource" id="TD_Office"><span>A6OK</span></td>
<td class="dow" id="TD_1" onDblClick="location.href('myurl.aspx?p=8&amp;e=0&amp;d=01-Mar-2011&amp;o=8&amp;v=A6OK');"></td>
<td class="dow" id="TD_2" onDblClick="location.href('myurl.aspx?p=8&amp;e=0&amp;d=02-Mar-2011&amp;o=8&amp;v=A6OK');"></td>
<td class="dow" id="TD_3" onDblClick="location.href('myurl.aspx?p=8&amp;e=0&amp;d=03-Mar-2011&amp;o=8&amp;v=A6OK');"></td>
<td class="dow" id="TD_4" onDblClick="location.href('.aspx?p=8&amp;e=0&amp;d=04-Mar-2011&amp;o=8&amp;v=A6OK');"></td>
<td class="weekend" id="TD_5" onDblClick="location.href('.aspx?p=8&amp;e=0&amp;d=05-Mar-2011&amp;o=8&amp;v=A6OK');"></td>
<td class="weekend" id="TD_6" onDblClick="location.href('myurl.aspx?p=8&amp;e=0&amp;d=06-Mar-2011&amp;o=8&amp;v=A6OK');"></td>
    .
    .
    .
and so on until end of month
    .   
    .
    .
</tr>
    .
    .
    .
and a bunch more similar rows
    .
    .
    .
</table>    

当文档准备好时,我对每个数据行执行一些操作,如下所示:

$('.DataRow').each(function(){  //do stuff  } );

当特定行的操作完成时,我希望隐藏该行中的“imgProgress”。 我在选择图像时遇到问题,以便将其显示设置为“无”

当前我正在 eloop 中尝试它,如下所示:

$(this).find(.imgProgress')attr('display', 'none');

我做错了什么?我如何选择图像?

I have a table on a page like so:

<table id="ctl00_PlaceHolderMain_Table_Name" class="schedule-table" cellspacing="1" border="0" style="width:100%;">
<tr>
    <td class="resource-header"><span class="resource-header-text">Personnel</span></td>
    <td class="resource-header"><span class="resource-header-text">Office</span></td>
    <td class="dow"><span class="dow">Tue<br>01</span></td><td class="dow"><span class="dow">Wed<br>02</span></td><td class="dow"><span class="dow">Thu<br>03</span></td><td class="dow"><span class="dow">Fri<br>04</span></td><td class="weekend"><span class="weekend-text">Sat<br>05</span></td><td class="weekend"><span class="weekend-text">Sun<br>06</span></td><td class="dow"><span class="dow">Mon<br>07</span></td>...and so on until end of month...<td class="dow"><span class="dow">Thu<br>31</span></td>
</tr>
<tr class="DataRow" id="DataRow_8">
<td class="resource" style="display:none;"><span class="resource">8</span></td>
<td class="resource" id="TD_Name"><img src="../../images/epas/working.gif" width="16" height="16" alt="Working..." id="imgProgress" /><span title="Lname, Fname " class="resource">Lname, Fname</span></td>
<td class="resource" id="TD_Office"><span>A6OK</span></td>
<td class="dow" id="TD_1" onDblClick="location.href('myurl.aspx?p=8&e=0&d=01-Mar-2011&o=8&v=A6OK');"></td>
<td class="dow" id="TD_2" onDblClick="location.href('myurl.aspx?p=8&e=0&d=02-Mar-2011&o=8&v=A6OK');"></td>
<td class="dow" id="TD_3" onDblClick="location.href('myurl.aspx?p=8&e=0&d=03-Mar-2011&o=8&v=A6OK');"></td>
<td class="dow" id="TD_4" onDblClick="location.href('.aspx?p=8&e=0&d=04-Mar-2011&o=8&v=A6OK');"></td>
<td class="weekend" id="TD_5" onDblClick="location.href('.aspx?p=8&e=0&d=05-Mar-2011&o=8&v=A6OK');"></td>
<td class="weekend" id="TD_6" onDblClick="location.href('myurl.aspx?p=8&e=0&d=06-Mar-2011&o=8&v=A6OK');"></td>
    .
    .
    .
and so on until end of month
    .   
    .
    .
</tr>
    .
    .
    .
and a bunch more similar rows
    .
    .
    .
</table>    

When the document is ready I perform some operations on each data row like so:

$('.DataRow').each(function(){  //do stuff  } );

When the operations are complete for a particular row I wish to hide the 'imgProgress' in that row.
I am having trouble selecting the image so that I can set its display to 'none'

Currently I am trying it within th eloop like so:

$(this).find(.imgProgress')attr('display', 'none');

What am I doing wrong? How can I select the image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

小巷里的女流氓 2024-10-29 18:20:24

以下应该有效:

$('#imgProgress').css('display','none');

The following should work:

$('#imgProgress').css('display','none');
成熟稳重的好男人 2024-10-29 18:20:24

由于 img 有一个 id(该 ID 在文档中必须是唯一的),请使用

$('#imgProgress');

:从文档中,您可以使用 jQuery .remove() 方法。

Since the img has an id (which must be unique within the document), use that:

$('#imgProgress');

To remove this from the document, you could use the jQuery .remove() method.

乱世争霸 2024-10-29 18:20:24

您的所有单元格上都有一个看起来并不唯一的 ID。将每个 TD 中的 ID 附加到类中,而不是作为 ID。

然后:

$(this).children('.TD_Name').children('img').css('display', 'none'); //where "this" is the TR object

All of your cells have an ID on them that does not look unique. Append that ID in each TD to the class instead of as an ID.

Then:

$(this).children('.TD_Name').children('img').css('display', 'none'); //where "this" is the TR object
孤单情人 2024-10-29 18:20:24

如果您在

或者将“this”更改为表格行的 ID/类。

$("#imgProgress", this) or $(this).find("#imgProgress") would select the imageProgress ID if you're performing your jQuery on the <td>

Or change "this" to the ID/Class of your table row.

千笙结 2024-10-29 18:20:24

好的一件事。不要在 DOM 中重复 ID 是一个坏主意,jquery 只能找到具有该 id 的某个选择器的第一个。

如果您处于某个 tr 的函数中,您可以更改该 tr 中的 img (带有类):

$('.DataRow').each(function(){ 
    //something in the tr...
    $($(this).children('td')[0]).children('.imgProgress').hide();
    //all done and hide this tr's img (in the 1st td)
})

ok for one thing. dont repeat IDs in the DOM is a bad idea and jquery only finds the 1st of a certain selector with that id.

if you are in a function for a certain tr you can change the img in that tr (with classes):

$('.DataRow').each(function(){ 
    //something in the tr...
    $($(this).children('td')[0]).children('.imgProgress').hide();
    //all done and hide this tr's img (in the 1st td)
})
满身野味 2024-10-29 18:20:24

HTML

使用 class="imgProgress" 代替

JS

将其更改为

$(this).find('.imgProgress').hide();

HTML

Use class="imgProgress" instead

JS

Change it to

$(this).find('.imgProgress').hide();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文