贴一个测试过的东西出来, 测试环境jQuery1.4.1
View Code
1 $(document).ready(function () {
2 $("#btnAddN").click(function () {
3 $("#DictNdata").append($("<option>", { value: $("#Option1").val() + "|" + $("#Option2").val(), text: $("#Option1").val() + "|" + $("#Option2").val() }));
4 insert_locations_updateLocationsHiddenField("1");
5 });
6 $("#btnMoveDownN").click(function () {
7 var selectedOption = $('#DictNdata > option:selected');
8 var nextOption = $('#DictNdata > option:selected').next("option");
9 if ($(nextOption).text() != "") {
10 $(selectedOption).remove();
11 $(nextOption).after($(selectedOption));
12 }
13 });
14 $("#btnMoveUpN").click(function () {
15 var selectedOption = $('#DictNdata > option:selected');
16 var prevOption = $('#DictNdata > option:selected').prev("option");
17 if ($(prevOption).text() != "") {
18 $(selectedOption).remove();
19 $(prevOption).before($(selectedOption));
20 }
21 });
22 $("#btnRemoveN").click(function () {
23 var selectedOption = $('#DictNdata > option:selected');
24 $(selectedOption).remove();
25 insert_locations_updateLocationsHiddenField("1");
26 });
27 $("#btnEditN").click(function () {
28 var selectedOption = $('#DictNdata > option:selected');
29 $(selectedOption).remove();
30 $("#DictNdata").append($("<option>", { value: $("#Option1").val() + "|" + $("#Option2").val(), text: $("#Option1").val() + "|" + $("#Option2").val() }));
31 insert_locations_updateLocationsHiddenField("1");
32 });
33 $('#DictNdata').change(function () {
34 var selectedOption = $('#DictNdata > option:selected').text();
35 $("input#Option1").val(selectedOption.split('|')[0]);
36 $("input#Option2").val(selectedOption.split('|')[1]);
37 });
38
39 $("#btnAdd").click(function () {
40 $("#Dictdata").append($("<option>", { value: $("#Option").val(), text: $("#Option").val() }));
41 insert_locations_updateLocationsHiddenField("0");
42 });
43 $("#btnMoveDown").click(function () {
44 var selectedOption = $('#Dictdata > option:selected');
45 var nextOption = $('#Dictdata > option:selected').next("option");
46 if ($(nextOption).text() != "") {
47 $(selectedOption).remove();
48 $(nextOption).after($(selectedOption));
49 }
50 });
51 $("#btnMoveUp").click(function () {
52 var selectedOption = $('#Dictdata > option:selected');
53 var prevOption = $('#Dictdata > option:selected').prev("option");
54 if ($(prevOption).text() != "") {
55 $(selectedOption).remove();
56 $(prevOption).before($(selectedOption));
57 }
58 });
59 $("#btnRemove").click(function () {
60 var selectedOption = $('#Dictdata > option:selected');
61 $(selectedOption).remove();
62 insert_locations_updateLocationsHiddenField("0");
63 });
64 $("#btnEdit").click(function () {
65 var selectedOption = $('#Dictdata > option:selected');
66 $(selectedOption).remove();
67 $("#Dictdata").append($("<option>", { value: $("#Option").val(), text: $("#Option").val() }));
68 insert_locations_updateLocationsHiddenField("0");
69 });
70 $('#Dictdata').change(function () {
71 $("input#Option").val($("#Dictdata option:selected").val());
72 });
73 });
2 $("#btnAddN").click(function () {
3 $("#DictNdata").append($("<option>", { value: $("#Option1").val() + "|" + $("#Option2").val(), text: $("#Option1").val() + "|" + $("#Option2").val() }));
4 insert_locations_updateLocationsHiddenField("1");
5 });
6 $("#btnMoveDownN").click(function () {
7 var selectedOption = $('#DictNdata > option:selected');
8 var nextOption = $('#DictNdata > option:selected').next("option");
9 if ($(nextOption).text() != "") {
10 $(selectedOption).remove();
11 $(nextOption).after($(selectedOption));
12 }
13 });
14 $("#btnMoveUpN").click(function () {
15 var selectedOption = $('#DictNdata > option:selected');
16 var prevOption = $('#DictNdata > option:selected').prev("option");
17 if ($(prevOption).text() != "") {
18 $(selectedOption).remove();
19 $(prevOption).before($(selectedOption));
20 }
21 });
22 $("#btnRemoveN").click(function () {
23 var selectedOption = $('#DictNdata > option:selected');
24 $(selectedOption).remove();
25 insert_locations_updateLocationsHiddenField("1");
26 });
27 $("#btnEditN").click(function () {
28 var selectedOption = $('#DictNdata > option:selected');
29 $(selectedOption).remove();
30 $("#DictNdata").append($("<option>", { value: $("#Option1").val() + "|" + $("#Option2").val(), text: $("#Option1").val() + "|" + $("#Option2").val() }));
31 insert_locations_updateLocationsHiddenField("1");
32 });
33 $('#DictNdata').change(function () {
34 var selectedOption = $('#DictNdata > option:selected').text();
35 $("input#Option1").val(selectedOption.split('|')[0]);
36 $("input#Option2").val(selectedOption.split('|')[1]);
37 });
38
39 $("#btnAdd").click(function () {
40 $("#Dictdata").append($("<option>", { value: $("#Option").val(), text: $("#Option").val() }));
41 insert_locations_updateLocationsHiddenField("0");
42 });
43 $("#btnMoveDown").click(function () {
44 var selectedOption = $('#Dictdata > option:selected');
45 var nextOption = $('#Dictdata > option:selected').next("option");
46 if ($(nextOption).text() != "") {
47 $(selectedOption).remove();
48 $(nextOption).after($(selectedOption));
49 }
50 });
51 $("#btnMoveUp").click(function () {
52 var selectedOption = $('#Dictdata > option:selected');
53 var prevOption = $('#Dictdata > option:selected').prev("option");
54 if ($(prevOption).text() != "") {
55 $(selectedOption).remove();
56 $(prevOption).before($(selectedOption));
57 }
58 });
59 $("#btnRemove").click(function () {
60 var selectedOption = $('#Dictdata > option:selected');
61 $(selectedOption).remove();
62 insert_locations_updateLocationsHiddenField("0");
63 });
64 $("#btnEdit").click(function () {
65 var selectedOption = $('#Dictdata > option:selected');
66 $(selectedOption).remove();
67 $("#Dictdata").append($("<option>", { value: $("#Option").val(), text: $("#Option").val() }));
68 insert_locations_updateLocationsHiddenField("0");
69 });
70 $('#Dictdata').change(function () {
71 $("input#Option").val($("#Dictdata option:selected").val());
72 });
73 });
View Code
1 <asp:TextBox ID="Option" runat="server" MaxLength="20"></asp:TextBox>
2 <input id="btnAdd" type="button" value="添加" />
3
4 <asp:ListBox ID="Dictdata" runat="server" Width="135px" SelectionMode="Single"></asp:ListBox>
5 <input id="btnEdit" type="button" value="修改" />
6 <input id="btnMoveUp" type="button" value="上移" />
7 <input id="btnMoveDown" type="button" value="下移" />
8 <input id="btnRemove" type="button" value="删除" />
9
2 <input id="btnAdd" type="button" value="添加" />
3
4 <asp:ListBox ID="Dictdata" runat="server" Width="135px" SelectionMode="Single"></asp:ListBox>
5 <input id="btnEdit" type="button" value="修改" />
6 <input id="btnMoveUp" type="button" value="上移" />
7 <input id="btnMoveDown" type="button" value="下移" />
8 <input id="btnRemove" type="button" value="删除" />
9