博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery – 随机排列 item
阅读量:7033 次
发布时间:2019-06-28

本文共 651 字,大约阅读时间需要 2 分钟。

有个项目需要用到随机排列按钮,写完顺便记录下 snippet。需求大概就是一堆按钮然后随机显示就行了,还是较简单的。

先看 ,再贴下 js 代码:

/* @author: Alan Ouyang
 * @param: {Object} args include: *parentId{String}
 * @description: 随机显示 items
 * -------------------------------------------------------*/
function randOrd() {
    return ( Math.round(Math.random()) - 0.5 );
}
function randomItem(args) {
    var $parent = $('#' + ars.parentId),    
        $item = $parent.children(),
        itemLength = $item.length;
    if (itemLength > 1) {
        $item.remove();
        var indices = [];
        for (var i = 0; i < itemLength; i++) { indices[indices.length] = i; }
        indices = indices.sort(randOrd);
        $.each(indices, function(j, k) { $parent.append($item.eq(k)); });
    }
}

转载地址:http://lhual.baihongyu.com/

你可能感兴趣的文章
Birt报表V4.3.2发布-2014.2.28
查看>>
MyBatis插入时候获取自增主键方法
查看>>
java对cookie的操作
查看>>
jQuery插件开发中$.extend和$.fn.extend辨析
查看>>
4_Oracle_Admin_Oracle的启动过程
查看>>
关于ulimit 打开文件数量
查看>>
安装LAMP
查看>>
(转)netlink简单实例
查看>>
Apache benchmark测试工具
查看>>
路由器终于配置成功了
查看>>
Linux常用命令及选项
查看>>
阿里云 的maven镜像
查看>>
ubuntu操作命令
查看>>
H.264参考软件JM12.2RC代码详细流程
查看>>
Bash脚本之循环
查看>>
cordova插件:inappbrowser
查看>>
Linux防火墙
查看>>
新手学习第一天
查看>>
如何在 IIS 上搭建 mercurial server
查看>>
linux字符集设置
查看>>