通过jQuery对随机字段项进行排序 [英] Sort random field items via jQuery

查看:135
本文介绍了通过jQuery对随机字段项进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML幻灯片菜单.具有以下内容:

I have a HTML slide menu. With the following:

<div class="slide">
<img typeof="foaf:Image" class="image-style-mylogo" src="http://site.com/1.png" alt="">
<img typeof="foaf:Image" class="image-style-mylogo" src="http://site.com/2.png" alt="">
<img typeof="foaf:Image" class="image-style-mylogo" src="http://site.com/3.png" alt="">
<img typeof="foaf:Image" class="image-style-mylogo" src="http://site.com/4.png" alt="">
<img typeof="foaf:Image" class="image-style-mylogo" src="http://site.com/5.png" alt="">
<img typeof="foaf:Image" class="image-style-mylogo" src="http://site.com/6.png" alt="">
</div>

我想在每次刷新时获取具有随机排序的图像.我使用了以下代码:

And i want, get images with random sort every refresh. I used this code:

function reorder() {
    var grp = $(".slide").children();
    var cnt = grp.length;

    var temp, x;
    for (var i = 0; i < cnt; i++) {
        temp = grp[i];
        x = Math.floor(Math.random() * cnt);
        grp[i] = grp[x];
        grp[x] = temp;
    }
    $(grp).remove();
    $(".slide").append($(grp));
}

function orderPosts() {
    $(".slide").html(orig);
}​

但是不行.我可能做错了什么?

But don't work. What might I be doing wrong?

推荐答案

您的reorder()函数很好,我在此小提琴中对其进行了测试: http://jsfiddle.net/kokoklems/YpjwE/

Your reorder() function is fine, I tested it in this fiddle : http://jsfiddle.net/kokoklems/YpjwE/

虽然我没有使用第二个功能orderPosts() ...

I did not used the second function orderPosts() though...

这篇关于通过jQuery对随机字段项进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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