您的位置:首页 > 其它

how to focus to a div both in firefox and IE

2007-07-24 12:38 501 查看
The following code work well in IE to focus to a div:

document.getElementById("div1").focus();

However, it doesn't work in firefox. You will not see any action taken after the line is executed. To workaround the issue, you can use the following code:

function getOffsetTop(el)

window.scrollTo(0,getOffsetTop(e));

getOffsetTop method is used to get the accurate top pixel of any element.

Here, window.scrollTo has two parameters. The first one represents offsetX and the second one represents offsetY. Here we only use the second parameter to scroll to the top border of the target control.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: