在jQuery中上移/下移 [英] move up/down in jquery

查看:194
本文介绍了在jQuery中上移/下移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个跨度,我试图在jquery中上下移动(交换位置)

I Have 5 spans i am trying to move them up/down (swap positions) in jquery

<a href="#" id="up">Up!</a> 
<a href="#" id="down">Down!</a>

<span id='1'>Test1</span><br>
<span id='2'>Test2</span><br>
<span id='3'>Test3</span><br>
<span id='4'>Test4</span><br>
<span id='5'>Test5</span>

我已经尝试过,但是什么也没发生.

i have tryed but nothing is happening.

 $("#"+LinkID).insertBefore($("#"+LinkID).next('span')); 

推荐答案

您正在尝试在下一个跨度之前插入某个跨度,以使其保持在相同位置...

You're trying to insert a certain span before the next one, which makes it remain on the same position...

$("#"+LinkID).insertBefore($("#"+LinkID).prev());

$("#"+LinkID).insertAfter($("#"+LinkID).next()); 

会更好.

这篇关于在jQuery中上移/下移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆