代码如下:
<select onchange ="onchange()">
<asp:Repeater runat ="server" ID ="groupRepeater">
<ItemTemplate >
<option id ='group<%#Eval("groupid") %>' value ='<%#Eval("groupid") %>'><%#Eval("groupname") %></option>
</ItemTemplate>
</asp:Repeater>
</select>
<script type="text/javascript">
function onchange(){
var index = $("select1").selectedIndex;
alert(index);
})
</script>
生成的HTML代码是什么样的?
这是生成页面后的代码:
<select onchange ="onchange()">
<option id ='group1' value ='1'>管理员</option>
<option id ='group2' value ='2'>版主</option>
<option id ='group3' value ='3'>会员</option>
<option id ='group4' value ='4'>禁言</option>
<option id ='group5' value ='5'>禁用</option>
</select>
@qiudan:
<select onchange ="onchange()">这一行换为:
<select id="select1" onchange ="change()">
一是加了一个id,后面好用来选取,二是把onchange()换为cnange()了,因为IE6下用onchange关键字不能触发事件
然后JS改为:
function change(){ var index = $("#select1").val(); alert(index); }
@artwl: 可以了,非常感谢!