开发者

Use JQuery to scroll ListBox (select box) to certain item

开发者 https://www.devze.com 2022-12-09 14:04 出处:网络
I have a list box control that contains enough items to list them with a scroll bar. I\'d like the user to be able to enter a few letters and have the ASP ListBox scroll to the first option whose tex

I have a list box control that contains enough items to list them with a scroll bar.

I'd like the user to be able to enter a few letters and have the ASP ListBox scroll to the first option whose text starts with those letters.

I'm hoping that JQuery offers some simple functionality or plug-in that works with the element, but so far, I've only seen plug-ins that work with scrolling DIVs.

Is there a way to scroll an ASP ListBox to a specified option?

EDIT

As @Alex Sexton stated, you can just se开发者_JS百科lect the option via javascript and it will scroll there automatically. Here is some simple JQuery to do just that:

$('#ListBox option:eq(6)').attr('selected', 'selected');


Your browser should handle the scroll automatically upon setting the selected attribute to "selected" on the element that you wish to put into view.

0

精彩评论

暂无评论...
验证码 换一张
取 消