我正在使用find来选择内部
$(".pauseAnomaly[data-id=78]").parent().parent().prev().find(".pauseaction").each(function (i) {
pauseActionUI($(this).data("id"));
});
我想在
.pauseAction
中找到的每个.pauseAction
上启动$(".pauseAnomaly[data-id=78]").parent().parent().prev().
在这里,当有一个
.pauseaction
时,它是完美的,但是当有多个.pauseaction
时,它什么都没有,为什么?以及如何解决这个问题?换一种说法
当我做
$(".pauseAnomaly[data-id=35]").parent().parent().prev().find(".pauseaction").each(function (i) {
alert($(this).data("id"));
});
哪里有一个
.pauseaction
,它返回一个id,但是当有多个.pauseaction
时,它返回我[]
,但是我很想看到所有id,并对所有它们应用funcito,为什么以及如何?我认为
find()
仅返回一个元素,因此,如果为true,我该如何进行更改以具有所有元素?这是我
$(".pauseAnomaly[data-id=14]").parent().parent().prev()
时的代码<table>
<tr>
<td style="border-top-width:0;padding-top:0;padding-left:0;padding-right:0;padding-bottom:0;">
<table class="table table-striped" style="margin-bottom:0;">
<tbody>
<tr class="actionRow actionRow" data-id="9">
<td><span class="glyphicon spaceAfterIcon vorx late glyphicon-remove red" data-id="9"></span></td>
<td>TEXT</td>
<td>TEXT</td>
<td class="date" data-id="9">03/04/2015</td>
<td>SELECT</td>
<td><span class="glyphicon glyphicon-comment commentAction red" data-actiondescr="Reparer le chauffage (date de fin plann. depassée)" data-actionid="9" data-id="9"></span> | <span class="glyphicon glyphicon-pause red pauseAction" data-id="9"></span> <span class="closeActionButtons" data-id="9">| <span class="glyphicon glyphicon-ok-circle red closeOKAction" data-id="9"></span>/ <span class="glyphicon glyphicon-remove-circle red closeNOKAction" data-id="9"></span></span></td>
</tr>
<tr class="actionRow desactivatedColor actionRow" data-id="10">
<td><span class="glyphicon spaceAfterIcon vorx late" data-id="10"></span></td>
<td>TEXT</td>
<td>TEXT</td>
<td class="date" data-id="10">03/04/2015</td>
<td>SELECT</td>
<td><span class="glyphicon glyphicon-comment commentAction red" data-actiondescr="Installer un thermostat pour réguler le chauffage" data-actionid="10" data-id="10"></span> | <span class=" glyphicon glyphicon-play red playAction" data-id="10"></span> <span class="closeActionButtons" data-id="10" style="display:none;">| <span class="glyphicon glyphicon-ok-circle red closeOKAction" data-id="10"></span>/<span class="glyphicon glyphicon-remove-circle red closeNOKAction" data-id="10"></span></span></td>
</tr>
<tr class="actionRow actionRow" data-id="13">
<td><span class="glyphicon spaceAfterIcon vorx late glyphicon-remove red" data-id="13"></span></td>
<td>TEXT</td>
<td>TEXT</td>
<td class="date" data-id="13">27/03/2012</td>
<td>SELECT</td>
<td><span class="glyphicon glyphicon-comment commentAction red" data-actiondescr="Action closed" data-actionid="13" data-id="13"></span> | <span class=" glyphicon glyphicon-pause red pauseAction" data-id="13"></span> <span class="closeActionButtons" data-id="13">| <span class="glyphicon glyphicon-ok-circle red closeOKAction" data-id="13"></span>/ <span class="glyphicon glyphicon-remove-circle red closeNOKAction" data-id="13"></span></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
最佳答案
问题在于选择器的情况,因为选择器必须是pauseAction
而不是pauseaction
。以下是一个说明它的演示。
$("table").find(".pauseAction").each(function (i) {
alert($(this).data("id"));
});
因此,您的代码将变为(提供的
.pauseAnomaly[data-id=14]
选择器存在!):$(".pauseAnomaly[data-id=14]").parent().parent().prev().find(".pauseAction").each(function (i) {
alert($(this).data("id"));
});
演示@ Fiddle