jQuery明确地使这种事情更容易一些。
鉴于这种简单的标记:
<div class="moveable" id="div1">
One
<a href='#' class="up">Move up</a>
<a href='#' class="down">Move down</a><br/>
</div>
<div class="moveable" id="div2">
Two
<a href='#' class="up">Move up</a>
<a href='#' class="down">Move down</a><br/>
</div>
<div class="moveable" id="div3">
Three
<a href='#' class="up">Move up</a>
<a href='#' class="down">Move down</a><br/>
</div>
这jQuery将移动元素向上或向下:
$('.moveable a.up').live('click',function(){
var $div = $(this).parent('.moveable');
var idx = $div.index();
if(idx>0){
$div.remove();
$('div.moveable:eq(' + (idx-1) +')').before($div);
}
return false;
});
$('.moveable a.down').live('click',function(){
var $div = $(this).parent('.moveable');
var idx = $div.index();
if(idx<$('div.moveable').length-1){
$div.remove();
$('div.moveable:eq(' + idx +')').after($div);
}
return false;
});
这应该给你足够的去开始做插入了。
这里的小提琴,如果你想有一个演示:http://jsfiddle.net/5hF98/
屏幕显示图像是无法访问 – kalpaitch 2010-07-28 12:10:05
你的截图是不是在发布的网址,使这个问题很混乱,没有它:) – 2010-07-28 12:10:17
将是很好,如果你可以发表评论/请在下面的帮助中标记为答案。 – Jamiec 2010-07-29 10:23:08