空空儿
Don't cry because it came to an end,smile because it happened.
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
posts - 43, comments - 121, trackbacks - 12
<
2007年4月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
与我联系
发短消息
搜索
留言簿
(7)
给我留言
查看留言
我参与的团队
武汉.NET俱乐部(0/538)
随笔分类
(53)
AJAX(6)
ASP.NET(14)
C# (9)
DataBase(7)
JAVASCRIPT(14)
O/R Mapping(2)
正则表达式(1)
资源链接
CodeProject
interface
a plugins of jquery
jQuery
stringtemplate
testdriven
最新随笔
1. 在C#里使用属性
2. Read text file (txt, csv, log, tab, fixed length)
3. 批量写数据---将XML数据批量写入数据库
4. 对对象类型和调用方法属性进行存储以提升反射性能
5. 过程 sp_addlinkedsrvlogin,第 91 行解密过程中出错的解决办法
6. 生成大量随机字符串不同实现方式的效率对比
7. 用SQL SERVER 2005新提供的命令实现行列转换
8. APM (异步编程模型)
9. 利用宏让ERStudio生成代码文件
10. 上传文件到FTP
最新评论
1. re: C#中对IP的一些操作
EnableStatic
在Win2000下和WinVista下不能报错,返回错误84 ,博主知道怎么解决吗?
--ted.cnblogs
2. re: javascript 里Array的一些方法
学习了
--hi.cxo
3. re: APM (异步编程模型)
原来不catch后果如此严重啊
下次得小心点了
--shawnliu
4. re: JS 实现 ListBox 上下移动项
mark
--lystory
5. re: ORACLE 常用函数
多谢:)
--ebreezee
阅读排行榜
1. javascript 里Array的一些方法(4006)
2. 使用HtmlParser解析HTML(3264)
3. 生成大量随机字符串不同实现方式的效率对比(2809)
4. 用SQL SERVER 2005新提供的命令实现行列转换(1998)
5. AJAX TreeView(1945)
评论排行榜
1. AJAX TreeView(26)
2. 在NHibernate里执行存储过程(24)
3. 用SQL SERVER 2005新提供的命令实现行列转换(10)
4. 生成大量随机字符串不同实现方式的效率对比(10)
5. 批量写数据---将XML数据批量写入数据库(9)
JS 实现 ListBox 上下移动项
1
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeBehind
=
"
WebForm3.aspx.cs
"
Inherits
=
"
test.WEB_APP.WebForm3
"
%>
2
3
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
4
5
<
html
xmlns
="http://www.w3.org/1999/xhtml"
dir
="ltr"
>
6
<
head
runat
="server"
>
7
<
title
>
无标题页
</
title
>
8
<
script
language
="Javascript"
type
="text/javascript"
>
9
var
obj , count,selectIndex,type;
10
var
MSG
=
[
{id:
1
,msg:
"
请选择要移动的项
"
}
,
11
{id:
2
,msg:
"
已是第一个无法上移
"
}
,
12
{id:
3
,msg:
"
已是最后一个无法下移
"
}
,
13
]
14
//
初始化相关数据
15
function
intial(t)
16
{
17
obj
=
rtObject();
18
count
=
ItemCount();
19
selectIndex
=
getSelectIndex();
20
type
=
t;
21
}
22
function
move(t)
23
{
24
intial(t);
25
if
(
!
check())
26
moveHandle();
27
}
28
function
moveHandle()
29
{
30
//
根据相关操作获得要变换位置的索引
31
var
operate
=
type
==
1
?
"
-1
"
:
"
+1
"
;
32
var
index
=
eval( selectIndex
+
operate);
33
34
var
values
=
obj.options[index].value;
35
var
text
=
obj.options[index].text;
36
obj.options[index].value
=
obj.options[selectIndex].value;
37
obj.options[index].text
=
obj.options[selectIndex].text;
38
obj.options[selectIndex].value
=
values;
39
obj.options[selectIndex].text
=
text;
40
41
obj.options[index].selected
=
true
;
42
}
43
//
检查是否可以移动
44
function
check()
45
{
46
var
bool
=
type
==
1
?
selectIndex
==
0
: selectIndex
==
count
-
1
;
47
if
(bool)
48
alert(MSG[type].msg);
49
return
bool;
50
}
51
//
获取当前选中项的索引
52
function
getSelectIndex()
53
{
54
var
index
=
-
1
;
55
for
(
var
i
=
0
; i
<
count ; i
++
)
56
{
57
if
(obj.options[i].selected)
58
{
59
index
=
i;
60
break
;
61
}
62
}
63
//
判断有没有选择移动项
64
if
(index
>=
0
)
65
return
index;
66
else
67
alert(MSG[
0
].msg);
68
}
69
//
获取项总数
70
function
ItemCount()
71
{
72
return
obj.options.length;
73
}
74
//
返回ListBox对象
75
function
rtObject()
76
{
77
return
document.form1.elements[
"
lb
"
];
78
}
79
</
script
>
80
</
head
>
81
<
body
>
82
<
form
id
="form1"
runat
="server"
>
83
<
div
>
84
<
asp:ListBox
ID
="lb"
runat
="server"
Height
="144px"
Width
="179px"
>
85
<
asp:ListItem
>
a
</
asp:ListItem
>
86
<
asp:ListItem
>
b
</
asp:ListItem
>
87
<
asp:ListItem
>
c
</
asp:ListItem
>
88
<
asp:ListItem
>
d
</
asp:ListItem
>
89
<
asp:ListItem
>
e
</
asp:ListItem
>
90
<
asp:ListItem
>
f
</
asp:ListItem
>
91
<
asp:ListItem
>
g
</
asp:ListItem
>
92
<
asp:ListItem
>
h
</
asp:ListItem
>
93
</
asp:ListBox
>
94
<
input
id
="Button1"
type
="button"
onclick
="move(1)"
value
="上移"
/>
95
<
input
id
="Button2"
type
="button"
onclick
="move(2)"
value
="下移"
/></
div
>
96
</
form
>
97
</
body
>
98
</
html
>
99
posted on 2007-04-02 19:32
空空儿
阅读(438)
评论(2)
编辑
收藏
网摘
所属分类:
JAVASCRIPT
Feedback
#1楼
2007-08-07 11:21 |
Penny [未注册用户]
太好了!正好有需要說!
感恩!
回复
引用
#2楼
2008-10-17 17:59 |
lystory
mark
回复
引用
查看
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
人才
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2007-08-26 18:26 编辑过
Google站内搜索
China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》
相关文章:
相关链接:
所属分类的其他文章:
JavaScript TreeView
让 FireFox 也支持 outerHTML
保存跨页面选择的数据
JavaScript里继承的实现
javascript 里的类实现
AJAX TreeView
javascript 里Array的一些方法
js 实现 将一个 ListBox 的项添加到另一个ListBox
JS 实现 ListBox 上下移动项
iframe自动适应文件大小
最新IT新闻:
51.com否认彩虹软件改名
彩虹QQ正式更名51彩虹 称“上QQ从51彩虹开始”
Jadu: 将 PHP 编译成 .NET
开心网遭多个山寨版复制围抢用户
微软表示Windows 7将直接在CPU上跑DirectX 10