如果在表格中的任何 td 上找不到焦点,则任务是采取措施。表格布局存储在 jquery变量中,其布局如下所示
<table class="cal_tbl" cellSpacing="1" cellPadding="3"> <tbody>
<tr>
<td class="cal_head"><<</td>
<td class="cal_head"><</td>
<td class="cal_head" colSpan="3">November 2012</td>
<td class="cal_head">></td>
<td class="cal_head">>></td>
</tr>
<tr>
<td class="cal_subhead">Sun</td>
<td class="cal_subhead">Mon</td>
<td class="cal_subhead">Tue</td>
<td class="cal_subhead">Wed</td>
<td class="cal_subhead">Thu</td>
<td class="cal_subhead">Fri</td>
<td class="cal_subhead">Sat</td>
</tr>
<tr>
<td colSpan="4"></td>
<td class="cal_cell">1</td>
<td class="cal_cell">2</td>
<td class="cal_cell">3</td>
</tr>
<tr>
<td class="cal_cell">4</td>
<td class="cal_cell">5</td>
<td class="cal_cell">6</td>
<td class="cal_cell">7</td>
<td class="cal_cell">8</td>
<td class="cal_cell">9</td>
<td class="cal_cell">10</td>
</tr>
<tr>
<td class="cal_cell">25</td>
<td class="cal_cell">26</td>
<td class="cal_cell">27</td>
<td class="cal_cell">28</td>
<td class="cal_cell">29</td>
<td class="cal_cell">30</td>
</tr> </tbody></table>
我必须检查焦点是否在任何 td 上 以下是我尝试的代码
if ($(CurrentCalendarButton).children[i].is(":focus") == true)
alert("Keep it on")
答案 0 :(得分:0)
问题在于DOM上的所有非元素实际上都接受焦点,并且由浏览器决定哪些元素可以。见Which HTML elements can receive focus?
也许您的 td :
上有悬停事件var hasFocus = false;
$('td').hover(
function () { hasFocus = true; alert('has focus !');},
function () { hasFocus = false; alert('lost focus !');}
);