jquery实现标签上移、下移、置顶
作者:hebedich 时间:2024-04-19 10:17:30
eg:如在后台的标签列表中,实现上移、下移、置顶功能
主要实现思路是节点操作,比如说:上移,直接把点击项移动到前一个节点,以此类推,当然实际代码实现还要加些判断,如当前点击操作项是否已经是置底或置底了,如果是则给点相应提示,好让操作者知道发生了什么事情。
思路:
1、先用到的克隆方法.clone(true):
即把当前要移动的项先保存好,备于后用。
2、找到当前标签所对应的相关元素及其相关方法:
如:.prev()当前元素上面的标签
.next()当前元素下面的标签
.after()xxx之后添加方法
.before()xxx之前添加方法
.prepend添加方法
3、实现
具体代码如:
var productsLabel = {
//设置置顶
setHot: function(t){
var bar = 'showAndHide_box';
var obj = $(t).parents('.'+bar).clone(true);
$(t).parents('.'+bar).remove();
$(".showAndHide_list_box").prepend(obj);
},
//设置上移
setUp: function(t){
var bar = 'showAndHide_box';
if($(t).parents('.'+ bar).prev('.'+bar).html() != undefined){
var obj = $(t).parents('.'+bar).clone(true);
$(t).parents('.'+bar).prev().before(obj);
$(t).parents('.'+bar).remove();
}else{
alert('亲,现在已是最上的哦,不能再上移了...');
}
},
//设置下移
setDown: function(t){
var bar = 'showAndHide_box';
if($(t).parents('.'+bar).next('.'+bar).html() != undefined){
var obj = $(t).parents('.'+bar).clone(true);
$(t).parents('.'+bar).next().after(obj);
$(t).parents('.'+bar).remove();
}else{
alert('亲,现在已是最下的哦,不能再下移了...');
}
}
}
标签:jquery,上移下移,jquery置顶
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决Python3错误:SyntaxError: unexpected EOF while parsin
2022-02-08 10:18:32
如何利用Fiddler模拟恶劣网络环境
2022-04-12 02:22:51
![](https://img.aspxhome.com/file/2023/6/131896_0s.png)
Python依赖管理及打包工具Poetry使用规范
2021-06-02 13:21:43
django中瀑布流写法实例代码
2022-08-04 11:11:26
![](https://img.aspxhome.com/file/2023/6/92366_0s.jpg)
Python内建类型str源码学习
2021-12-24 22:24:33
![](https://img.aspxhome.com/file/2023/3/90643_0s.png)
Python时间转化方法超全总结
2021-10-23 02:39:56
![](https://img.aspxhome.com/file/2023/9/133349_0s.jpg)
Python全面分析系统的时域特性和频率域特性
2022-12-04 06:32:12
![](https://img.aspxhome.com/file/2023/7/113137_0s.jpg)
详解如何创建Python元类
2023-09-20 04:50:15
![](https://img.aspxhome.com/file/2023/6/133446_0s.jpg)
Django drf使用Django自带的用户系统的注册功能
2023-07-15 00:21:38
![](https://img.aspxhome.com/file/2023/9/121499_0s.jpg)
利用Python绘制创意中秋节月饼
2023-02-19 17:52:41
![](https://img.aspxhome.com/file/2023/5/97425_0s.jpg)
自动完成JS类(纯JS, Ajax模式)
2024-05-11 09:41:59
![](https://img.aspxhome.com/file/2023/9/125949_0s.jpg)
python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests
2022-07-17 05:39:02
![](https://img.aspxhome.com/file/2023/4/92114_0s.jpg)
SQLserver 2005文件和文件组的作用说明
2024-01-26 09:45:57
Mysql的longblob字段插入数据问题解决
2024-01-24 09:49:52
Keras中的多分类损失函数用法categorical_crossentropy
2023-06-23 12:25:37
![](https://img.aspxhome.com/file/2023/5/63935_0s.jpg)
你是真正的用户体验设计者吗? Ⅴ
2008-04-19 18:32:00
![](https://img.aspxhome.com/file/UploadPic/20084/19/2008419215352323s.jpg)
PHP GD 图像处理组件的常用函数总结
2023-11-21 21:39:17
sqlserver主键设计的注意点
2024-01-18 08:30:30
MyBatis批量插入/修改/删除MySql数据
2024-01-18 05:55:11
![](https://img.aspxhome.com/file/2023/0/108420_0s.png)
asp 在线备份与恢复sql server数据库的代码
2010-07-31 18:52:00