查找父td标签并禁用点击

时间:2019-05-24 18:03:24

标签: javascript onclick

找到主要的父td标签并禁用click事件:

HTML:

<tr>
<td id="" class="tg-tue">2:30</td>
<td id="selectedtimetemptue230" onclick="makeChangeTuesday(3,0,1,'tuesday',0,'2:30',0)" class="tg-tue availablepopup">
<a href="#" class="occupypopup"><span class="tempclr noclr text-bold">X</span></a><br>
</td>
</tr>

<tr>
<td id="" class="tg-tue">3:30</td>
<td id="selectedtimetemptue330" onclick="makeChangeTuesday(3,0,1,'tuesday',0,'2:30',0)" class="tg-tue availablepopup">
<a href="#" class="occupypopup"><span class="tempclr noclr text-bold">X</span></a><br>
</td>
</tr>

<tr>
<td id="" class="tg-tue">4:30</td>
<td id="selectedtimetemptue430" onclick="makeChangeTuesday(3,0,1,'tuesday',0,'2:30',0)" class="tg-tue availablepopup">
<a href="#" class="occupypopup"><span class="noclr text-bold">X</span></a><br>
</td>
</tr>

文章:

var tempclr = $(".tempclr").length;
if(tempclr > 0) {
    // this will add class for first 2 tr tags                                                                                                                                                                                                                                                                        
    $(".tempclr").addClass('test123');
}

1 个答案:

答案 0 :(得分:0)

这会在找到类onclick的每个表单元格中禁用tempclr

var tabdat = document.querySelectorAll('table tr td:last-of-type');
var href = document.getElementsByTagName("a");
for (var i=0; i < tabdat.length; i++) { 
if(href[i].innerHTML.indexOf('tempclr') != -1 ) {
tabdat[i].onclick = false;
   }
}