Asp.net 中 listbox 滚动条 定位 火麒

<asp:ListBox ID="lbResearcher" runat="server" Width="130px" Rows="12" AutoPostBack="true"

OnSelectedIndexChanged="lbResearcher_SelectedIndexChanged" SelectionMode="Multiple" ToolTip="单击"

CssClass="uc_lbResearcher" ></asp:ListBox>

// 滚动条的选中位置

function ScrollSelectedHeight(allcount, index) { 

//滚动条的总高度

var allHeight = $(".uc_lbResearcher")[0].scrollHeight; 

//选中项在listbox的中间位置

$(".uc_lbResearcher").scrollTop((index / allcount) * allHeight - $(".uc_lbResearcher").height()/2); 

protected void lbResearcher_SelectedIndexChanged(object sender, EventArgs e) 

///

//后台要处理的功能代码

///

//定位滚动条的高度 执行前台js方法

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "key", "ScrollSelectedHeight('" + lbResearcher.Items.Count + "','" + lbResearcher.SelectedIndex + "');", true); 

原文地址:https://www.cnblogs.com/firekylin/p/2143033.html