【问题标题】:How can I get the indices of children in a HTML ul sortable list, using jQuery/javascript?如何使用 jQuery/javascript 在 HTML ul 可排序列表中获取子项的索引?
【发布时间】:2011-11-11 01:21:31
【问题描述】:

我有一个动态填充的列表,我想获取该列表子项的索引。 该列表是一个无序的可排序列表,使用 jQuery 创建。

代码如下:

 $(function getIndex(){
            var i=0;
            for (i = 0; i < $("#questionList").length; i++)
                questionOrder[i] = $("#questionList").children().index(); //not working
    }); 

【问题讨论】:

  • 你能给出更详细的代码吗?如果可以,请在 jsfiddle 上发布一个示例列表以及您的代码,以便我对其进行测试,看看您做错了什么...

标签: javascript jquery html jquery-ui-sortable html-lists


【解决方案1】:

试试这个:

$(function getIndex(){
            var i=0;
            for (i = 0; i < $("#questionList").length; i++)
                questionOrder[i] = $("#questionList").children().get(i).index();
    }); 

您必须在该子数组中获取特定子元素,然后获取索引

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多