我正在尝试使这个可选脚本具有选择限制。我希望它在选择限制超过限制数 4 时停止选择。
$(function() {
$(".selectable").selectable({
filter: "td.cs",
stop: function() {
var result = $("#select-result").empty();
var result2 = $("#result2");
$('.ui-selecting:gt(31)').removeClass("ui-selecting");
// alert($(".ui-selected").length);
$('#divmsg').html($(".ui-selected").length*2+ " box selected")
if ($(".ui-selected").length > 4) {
//alert("Selection of only 4 allowed");
$('#divmsg').html($('#divmsg').html() + ", Selection of only 4 allowed");
$(".ui-selected").each(function(i, e) {
if (i > 3) {
$(this).removeClass("ui-selected");
}
});
return;
}
$(".ui-selected", this).each(function() {
var cabbage = this.id + ', ';
result.append(cabbage);
});
var newInputResult = $('#select-result').text();
newInputResult = newInputResult.substring(0, newInputResult.length - 1);
result2.val(newInputResult);
}
});
});
谢谢你