62,256
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDownList.aspx.cs" Inherits="DropDownList" %>
<!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">
function add()
{
var text=document.getElementById("Text1").value;
var value=document.getElementById("Text2").value;
document.getElementById("ddl").options[document.getElementById("ddl").length]= new Option(text,value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddl" runat="server" Width="127px">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
<asp:ListItem>E</asp:ListItem>
</asp:DropDownList> <br />
text: <input id="Text1" style="width: 56px" type="text" />
value: <input id="Text2" style="width: 55px" type="text" /><br />
<input id="Button2" type="button" value="添加" onclick="add();"/>
<input id="Button1" type="button" value="清空" onclick="javascript:document.getElementById('ddl').options.length=0;" />
</div>
</form>
</body>
</html>
function add_option( name , texts , value )
{
var selObj = getElement( name );
selObj.options[selObj.length]=new Option( texts , value );
}