<script language ="javascript" type ="text/javascript">
function Button1_onclick() {
var listbox = document.getElementById('ListBox1')
var option = document.createElement("OPTION")
option.value = 1
option.text ='ABC'
listbox.add(option)
}
</script>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick()
{
var obj=document.getElementsByTagName("option")
for(var i=0i<obj.lengthi++)
{
if(obj[i].selected==true)
{
alert(obj[i].value)
//也可以得到obj[i]的text
}
}
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="Listbox1" runat="server">
<asp:ListItem Value="00">0</asp:ListItem>
<asp:ListItem Value="11">1</asp:ListItem>
<asp:ListItem Value="22">2</asp:ListItem>
</asp:ListBox>
</div>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
</form>
</body>
</html>
这个方法仅限于页面中只有一个listbox,如果多个的话,第一步是先得到你要用的listbox,然后再这样
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)