2
我简单的问题是,$ 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'方法中缺少'return'语句 – Esailija