无法集中精力在FF工作

时间:2012-08-24 23:22:15

标签: javascript dom timeout focus dom-manipulation

它在IE中工作正常但在FF中没有任何作用。

这是我正在使用它的代码。 该代码为proboards.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);

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

这是因为DOM表元素没有focus方法(虽然它是在IE中实现的)。我假设你需要滚动到那个元素,所以你可以这样做:

window.scrollTo(0,table.scrollHeight);

或者在您的确切代码中:

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