1<%@ Page language="c#" Codebehind="ddlWriteControl.aspx.cs" AutoEventWireup="false" Inherits="WebDemo.ddlWriteControl" %>
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3<HTML>
4 <HEAD>
5 <title>ddlWriteControl</title>
6 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
7 <meta name="CODE_LANGUAGE" Content="C#">
8 <meta name="vs_defaultClientScript" content="JavaScript">
9 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10 <style> #div1 { Z-INDEX: 1; LEFT: 250px; WIDTH: 216px; CLIP: rect(3px 280px 21px 110px); POSITION: absolute; TOP: 89px; HEIGHT: 72px } #div2 { LEFT: 250px; WIDTH: 95px; POSITION: absolute; TOP: 89px; HEIGHT: 18px; 2: } </style>
11 </HEAD>
12 <body MS_POSITIONING="GridLayout">
13 <script language="javascript">
14 function AddOption()
15 {
16 var val = document.getElementById("txtValue").value;
17 var option = document.getElementById("ddl");
18
19 if(val == "")
20 {
21 alert("请输入项值");
22 return;
23 }
24 if(option.length > 0)
25 {
26 for(var i=0;i<option.length;i++)
27 {
28 if(option.options[i].value == val)
29 {
30 alert("该值已存在!");
31 return;
32 }
33 }
34 }
35
36 var option_val = new Option(val,val);
37
38 option.add(option_val);
39 option.selectedIndex = option.options.length-1;
40
41 }
42 </script>
43 <form id="Form1" method="post" runat="server">
44 <div id="div1" style="Z-INDEX: 101; WIDTH: 128px; HEIGHT: 72px">
45 <asp:DropDownList id="ddl" onchange="document.getElementById('txtValue').value = this.value" runat="server"
46 Width="127">
47 <asp:ListItem Value="aaa1">aaa1</asp:ListItem>
48 <asp:ListItem Value="bbb2">bbb2</asp:ListItem>
49 <asp:ListItem Value="ccc3">ccc3</asp:ListItem>
50 </asp:DropDownList>
51 </div>
52 <FONT face="宋体"></FONT>
53 <div id="div2">
54 <asp:TextBox id="txtValue" style="PADDING-LEFT:2px;PADDING-TOP:2px" runat="server" Width="127"></asp:TextBox>
55 <input type="button" value="OK" id="btn" onclick="AddOption();">
56 </div>
57
58 </form>
59 </body>
60</HTML>
61
如果有问题请与我联系。
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3<HTML>
4 <HEAD>
5 <title>ddlWriteControl</title>
6 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
7 <meta name="CODE_LANGUAGE" Content="C#">
8 <meta name="vs_defaultClientScript" content="JavaScript">
9 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10 <style> #div1 { Z-INDEX: 1; LEFT: 250px; WIDTH: 216px; CLIP: rect(3px 280px 21px 110px); POSITION: absolute; TOP: 89px; HEIGHT: 72px } #div2 { LEFT: 250px; WIDTH: 95px; POSITION: absolute; TOP: 89px; HEIGHT: 18px; 2: } </style>
11 </HEAD>
12 <body MS_POSITIONING="GridLayout">
13 <script language="javascript">
14 function AddOption()
15 {
16 var val = document.getElementById("txtValue").value;
17 var option = document.getElementById("ddl");
18
19 if(val == "")
20 {
21 alert("请输入项值");
22 return;
23 }
24 if(option.length > 0)
25 {
26 for(var i=0;i<option.length;i++)
27 {
28 if(option.options[i].value == val)
29 {
30 alert("该值已存在!");
31 return;
32 }
33 }
34 }
35
36 var option_val = new Option(val,val);
37
38 option.add(option_val);
39 option.selectedIndex = option.options.length-1;
40
41 }
42 </script>
43 <form id="Form1" method="post" runat="server">
44 <div id="div1" style="Z-INDEX: 101; WIDTH: 128px; HEIGHT: 72px">
45 <asp:DropDownList id="ddl" onchange="document.getElementById('txtValue').value = this.value" runat="server"
46 Width="127">
47 <asp:ListItem Value="aaa1">aaa1</asp:ListItem>
48 <asp:ListItem Value="bbb2">bbb2</asp:ListItem>
49 <asp:ListItem Value="ccc3">ccc3</asp:ListItem>
50 </asp:DropDownList>
51 </div>
52 <FONT face="宋体"></FONT>
53 <div id="div2">
54 <asp:TextBox id="txtValue" style="PADDING-LEFT:2px;PADDING-TOP:2px" runat="server" Width="127"></asp:TextBox>
55 <input type="button" value="OK" id="btn" onclick="AddOption();">
56 </div>
57
58 </form>
59 </body>
60</HTML>
61