我遵循以下问题实现了“全选”功能:How to programmatically select selectables with jQuery UI?
select all按钮在执行._mouseStop命令时工作得很好,然后它只会显示错误:
Uncaught TypeError: Cannot call method '_mouseStop' of undefined 以下是代码的相关部分:
步骤1:此页面上有四个列表,并且所有四个列表都使用可选择插件
//Make all four lists selectable
$("#selectNewTweets").selectable();
$("#selectApprovedTweets").selectable();
$("#selectDeclinedTweets").selectable();
$("#selectUndecidedTweets").selectable();步骤2:批量注册所有“全选”按钮(每个列表一个)
//click a "Select All" button
$("[id^=btnSelectAll]").click(function(e){
var id = $(this).attr('id');
var list = id.substring(
"btnSelectAll".length,
id.length);
//select all elements in target list
$("#select"+list+"Tweets > li").each(function(index){
$(this).removeClass('ui-selected');
$(this).addClass("ui-selecting");
});
$("#select"+list+"Tweets").data("selectable")._mouseStop(null);
});当我单击任何"Select All“按钮时,里面的元素都会得到"ui-selecting”类,所以.each()语句可以很好地工作。但是,一旦它到达._mouseStop()行,它就会抛出我上面提到的异常。
你知道是什么导致了异常吗?
发布于 2013-06-09 10:01:52
如果您注意到所引用的StackOverflow问题的选定答案的this comment,则说明对于更高版本的jQuery UI库,您应该使用.data("ui-selectable")而不是.data("selectable")。希望这就是你得到错误的原因,因为我认为你的代码没有其他问题。
https://stackoverflow.com/questions/17001828
复制相似问题