我有一个多选<asp:listbox>
和一个按钮。我想禁用该按钮,除非选择了列表框中 >= 1 项。我该如何做这个客户端?我找不到某种OnSelect
回调,仅OnSelectedIndexChanged
从谷歌搜索看来,这种行为使用起来很复杂,可能是不可能的。
最佳答案
使用OnChange事件,并对所选项目进行计数:
<script>function enableButton(opt) {
var selected = new Array();
var count = 0;
for (var intLoop=0; intLoop < opt.length; intLoop++) {
if (opt[intLoop].selected) {
count++;
}
}
if (count >= 1)
{
// disable button
}
}
</script>
<select id="list" style="font-size: 11px;"
onChange="enableButton(this.options);" MULTIPLE SIZE="5">
<option value="0">Select...</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
编辑: ASP:ListBox 呈现为 HTML 作为选择,如上面的代码。因此,您需要做的就是在 onchange 属性中添加脚本:
myListBox.Attributes.Add("onchange", "enableButton(this.options);");
关于asp.net - 相当于多选 asp 列表框中的 OnSelect javascript Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1380148/