[英]can't filter jQuery click off class definition
I have a table set up... here is the relevant HTML format... 我已经建立了表格...这是相关的HTML格式...
<table class="booking table">
<tbody class="time_period_rows">
<tr class>
<td> ... </td>
</tr>
<tr class="booked">
<td> ... </td>
</tr>
.
.
<tr class="selected">
<td> ... </td>
</tr>
And the table goes on from there. 桌子从那里继续。 Fundamentally I have table of appointment slots.
从根本上讲,我有约会空档表。 The "booked" class means exactly that.
“已预订”类的确切含义是。 The "selected" class is toggled on and off as a the time for a new booking is selected.
随着选择新预订的时间,“选择的”类别被打开和关闭。 I simply want to stop a click being recognised when they try and select one where the "booked" class exists.
我只是想在他们尝试尝试单击并选择存在“已预订”课程的地方时停止识别单击。 Here is my current jQuery code,
这是我当前的jQuery代码,
$('.time_period_rows tr:not(.booked)').click(function(){
$('.selected').removeClass('selected');
$(this).toggleClass('selected');
});
Pretty darn simple. 很简单。 But the filtering is not working.
但是过滤不起作用。 Right now I can select any row.
现在,我可以选择任何行。 Can anyone see why?
谁能看到原因?
Many Thanks 非常感谢
您只需要取消绑定单击,因为<tr>
已添加booked
的课程:
$(this).unbind('click');
$('.time_period_rows tr').on('click', function(){
if (!$(this).is('.booked')) {
$('.selected').removeClass('selected');
$(this).toggleClass('selected');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.