如何使用javascript / jquery关注给定表的行?

如何使用javascript / jquery关注给定表的行?

问题描述:

有一个大的html表,其中有许多行不适合屏幕,你知道如何使用javascript / jquery关注给定行,避免向下滚动吗?

Having a big html table with many rows that does not fit on the screen, do you know how to focus on a given row with javascript/jquery avoiding the need to scroll down?

查找scrollIntoView函数。通过(我认为)所有浏览器支持大多数元素。

Look up the "scrollIntoView" function. It's supported on most elements by (I think) all the browsers.

当我想制作一个表(或者像表格之类的东西)时,我做了什么,我确保目标表行有一个特殊的类,或者可能是id值。然后我可以使用Javascript找到该行并调用scrollIntoView()。你唯一需要注意的是,IE有时会混淆并搞砸桌子周围的布局,但是如果你小心设置可滚动元素,通常可以使它工作。

What I do, when I want to make a table (or something like a table) behave that way, I make sure that the target table row has a special class, or maybe an "id" value. Then I can find the row with Javascript and call "scrollIntoView()". The only thing you have to watch out for is that sometimes IE gets confused and screws up layout around the table, but if you're careful with how you set up scrollable elements it usually can be made to work.