我試圖將點擊事件只添加到在第一列有一些文本的行中的列。 對於第一行,單擊事件應該隱藏第一列中包含「1 /」的行。 這裏是我的HTML表格:jquery爲自定義行添加事件不起作用
<table class="results">
<tr>
<td>1</td>
<td>Distribution_Approval_Archive_WorkFLow</td>
<td>0h:2m:59s:845ms</td>
<td><font color="red">TestFail</font></td>
</tr>
<tr>
<td>1/1</td>
<td>MyLogin</td>
<td>0h:0m:8s:298ms</td>
<td><font color="green">TestCasePass</font></td>
</tr>
<tr>
<td>1/2</td>
<td>OpenEFlowEnterprise</td>
<td>0h:0m:13s:912ms</td>
<td><font color="green">TestCasePass</font></td>
</tr>
<tr>
<td>2</td>
<td>Distribution_Approval_Archive_WorkFLow</td>
<td>0h:2m:59s:845ms</td>
<td><font color="red">TestFail</font></td>
</tr>
<tr>
<td>2/1</td>
<td>MyVismaLogin</td>
<td>0h:0m:6s:223ms</td>
<td><font color="green">TestCasePass</font></td>
</tr>
<tr>
<td>2/2</td>
<td>OpenEFlowEnterprise</td>
<td>0h:0m:5s:158ms</td>
<td><font color="green">TestCasePass</font></td>
</tr>
</table>
這裏是我的jQuery添加事件:
for (i=1; i <= $(".results td:nth-child(1):not(:contains('/'))").parent().length; i++){
$($(".results td:nth-child(1):not(:contains('/'))").parent()[i-1]).children().click(function(){
$('.results td:nth-child(1):contains("'+ i +'/")').parent().slideToggle("fast");
})
}
你幫助解決問題的jQuery代碼?在循環
我m不知道'.parent()'會返回多於1個元素。 – putvande
parent()僅從評估選擇器的每個元素返回一個元素;但是,循環是問題 – danginkgo