- <!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>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <script src1="js/jquery-1.8.3.js"></script>
- <style>
- .pt{
- line-height:22px;
- width:280px;
- }
- div a{
- float:right ;
- margin-right:5px;
- }
- </style>
- <script>
- function up(obj){
- var _div = $(obj).parent() ,
- _divp = _div.parent() ,
- _divs = _divp.children("div") ,
- _divindex = _divs.index(_div);
- if(_divindex>0){
- _divs.eq(_divindex-1).before(_div);
- }
- }
- function down(obj){
- var _div = $(obj).parent() ,
- _divp = _div.parent() ,
- _divs = _divp.children("div") ,
- _divindex = _divs.index(_div);
- if(_divindex<_divs.length-1){
- _divs.eq(_divindex+1).after(_div);
- }
- }
- </script>
- </head>
- <body>
- <div>
- <div class="pt">
- <a href="javascript:;" onclick="up(this);">上移</a>
- <a href="javascript:;" onclick="down(this);">下移</a>
- <span>内容一</span>
- </div>
- <div class="pt">
- <a href="javascript:;" onclick="up(this);">上移</a>
- <a href="javascript:;" onclick="down(this);">下移</a>
- <span>内容二</span>
- </div>
- </div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/140320149015.html
来源: http://www.codesnippet.cn/detail/140320149015.html