如何选择表格行中的图像?
我在页面上有一个表格,如下所示:
<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>
当文档准备好时,我对每个数据行执行一些操作,如下所示:
$('.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下应该有效:
The following should work:
由于
img
有一个id
(该 ID 在文档中必须是唯一的),请使用:从文档中,您可以使用 jQuery
.remove()
方法。Since the
img
has anid
(which must be unique within the document), use that:To remove this from the document, you could use the jQuery
.remove()
method.您的所有单元格上都有一个看起来并不唯一的 ID。将每个 TD 中的 ID 附加到类中,而不是作为 ID。
然后:
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”更改为表格行的 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.
好的一件事。不要在 DOM 中重复 ID 是一个坏主意,jquery 只能找到具有该 id 的某个选择器的第一个。
如果您处于某个 tr 的函数中,您可以更改该 tr 中的 img (带有类):
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):
HTML
使用
class="imgProgress"
代替JS
将其更改为
HTML
Use
class="imgProgress"
insteadJS
Change it to