我想使用jquery获取列表框中存在的所有列表项,如果选择与否则无关紧要.
这是我的客户端脚本:
<asp:ListBox ID="lstSelected" runat="server" SelectionMode="Multiple" Rows="10">
<asp:ListItem Value="Employee_OID">EID</asp:ListItem>
<asp:ListItem Value="EmpID">Emp ID</asp:ListItem>
<asp:ListItem Value="Employee_Name">Name</asp:ListItem>
</asp:ListBox>
Run Code Online (Sandbox Code Playgroud)
通过向ListBox添加静态ID(ClientIDMode ="Static")生成,您可以直接在jQuery中使用ID属性值(跳过ClientID用法):
<asp:ListBox ID="lstSelected" runat="server" SelectionMode="Multiple" Rows="10" ClientIDMode="Static">
<asp:ListItem Value="Employee_OID">EID</asp:ListItem>
<asp:ListItem Value="EmpID">Emp ID</asp:ListItem>
<asp:ListItem Value="Employee_Name">Name</asp:ListItem>
</asp:ListBox>
Run Code Online (Sandbox Code Playgroud)
jQuery获取所有选项:
$('#lstSelected option')
Run Code Online (Sandbox Code Playgroud)
jQuery获取所有选定的选项:
$('#lstSelected option:selected')
Run Code Online (Sandbox Code Playgroud)
在ClientIDMode上查看更多信息:http: //msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx
| 归档时间: |
|
| 查看次数: |
11672 次 |
| 最近记录: |