如何聚焦< tr>或< td>使用jQuery或JavaScript标记?
问题描述:
for(var i=0;i<tr.length;i++){
var td = tr[i].getElementsByTagName("td");
if(td[2].innerHTML==time && td[3].innerHTML==cls){
td[0].setAttribute("id","focus");
tr[i].style.backgroundColor="green";
var foc = document.getElementById("focus");
foc.focus();
cnt++;
}
else{
tr[i].style.backgroundColor="transparent";
}
}
答
这已经为时已晚,但是您 CAN 专注于TD元素.只需为其提供一个tabindex属性,然后执行focus().
This is a year too late, but you CAN focus to a TD element. Just give it a tabindex property, and then do a focus().
这适用于DIV元素和几乎所有其他元素.
This works for DIV elements and almost all others.
我已经在Firefox 3.5及更高版本上尝试过此操作.
I've tried this on Firefox 3.5 and up.