合十礼!
我的简单问题是 $sortedData 在执行时在以下代码中变为未定义:
(function($) {
$.fn.shuffle = function (){
var i = this.length, j, temp;
if ( i == 0 ) { return; }
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
};
})(jQuery);
// DOMContentLoaded
$(function() {
// get the first collection
var $cards = $('#cards');
// clone cards to get a second collection
var $data = $cards.clone();
// call Quicksand when button clicked
$('#shuffle').click(function(e) {
// get all the list items
var $filteredData = $data.find('li');
// random sort (shuffling)
var $sortedData = $filteredData.shuffle();
// finally, call quicksand
$cards.quicksand($sortedData, {
duration: 600,
easing: 'easeInOutQuad'
});
});
});
这是如何调用的:我有一个按钮,单击该按钮时会执行上述代码。
我已经在调用 shuffle 函数之前检查了 shuffle 函数中的值,但是,当 shuffle 函数返回时,$sortedData 未定义。
这个错误可能是一个小问题,但是,我看不到它。
感谢您的投入!
最佳答案
您的“shuffle”函数不会返回任何内容,但您将其视为返回值。它似乎就地洗牌。
关于javascript - jQuery "array"返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8216004/