可以'我没有集中精力在FF工作

Can't get focus to work in FF

本文关键字:集中精力 FF 工作 可以      更新时间:2023-09-26

它在IE中运行良好,但在FF中无效。

这是我正在使用的代码。该代码为probboards.com做了一些事情。我认为在这种情况下,对代码的解释是无关紧要的。如果没有,请告诉我。

但重点部分只是把重点放在一个单一的元素上。

这是代码:

<script>
var TitleBarGuestMessage="Hello Guest!";
var TitleBarMemberMessage="Welcome Back "+pb_displayname+"!";
var i,table,LTPI,LTPItable,titlerow,titlerowcell1,LTPIrow,LTPIrowcell1,shortcutA,shortcutB,shortcutC,
td=document.getElementsByTagName("td");LTPItable= document.getElementById("rectangle_table");LTPI=document.getElementById("rectangle_right_side");LTPItable.style.width="100%";
shortcutA=LTPI.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
shortcutB=shortcutA.previousSibling.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;shortcutC=shortcutA.firstChild;
shortcutA.previousSibling.parentNode.parentNode.cellSpacing="0";
shortcutA.previousSibling.style.display="none";
shortcutB.className="";
shortcutB.bgColor="transparent";
shortcutC.align="center";
shortcutC.style.backgroundColor="transparent";
shortcutC.className="";
LTPI.style.display="none";
for(i=0;i<td.length;i++){
if(td[i].className=="titlebg" && td[i].colSpan=="2"){
td[i].parentNode.parentNode.parentNode.id="forum";}}
table=document.getElementById("forum");
if(pb_action=="home"){
setTimeout(function(){table.focus();}, 2000)};
titlerow=table.insertRow(0);
titlerowcell1=titlerow.insertCell(0);
titlerowcell1.className="titlebg";
titlerowcell1.colSpan="5";
titlerowcell1.id="LTPI_titlebar";
LTPIrow=table.insertRow(1);
LTPIrowcell1=LTPIrow.insertCell(0);
LTPIrowcell1.colSpan="5";
LTPIrowcell1.innerHTML=LTPI.innerHTML;
LTPIrowcell1.id="LTPI_row";
if(pb_username=="Guest"){
titlerowcell1.innerHTML=TitleBarGuestMessage}
else{titlerowcell1.innerHTML=TitleBarMemberMessage}
</script>

这是脚本的重点部分:

if(pb_action=="home"){
    setTimeout(function(){table.focus();}, 2000)};

我也试过:

setTimeout("table.focus();",2000);

有什么建议吗?

这是因为DOM表元素没有focus方法(尽管它是在IE中实现的)。我假设你需要滚动到那个元素,所以你可以这样做:
window.scrollTo(0,table.scrollHeight);

或者就像你的确切代码一样:

if(pb_action=="home"){
    setTimeout(function(){window.scrollTo(0,table.scrollHeight)}, 2000)};