我试图添加6个可选行的限制,但我无法使其工作。任何帮助!!

<script>
$(function() {
  $(".selectable").selectable({
      filter: "td.cs",


      stop: function() {
          var result = $("#select-result").empty();
          var result2 = $("#result2");
          $(".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);
      }
  });
 });​
 </script>


提前致谢!!!

最佳答案

您可以使用selecting事件回调执行此操作,如下所示

$( "#selectable" ).selectable({
   selecting: function(event, ui) {
     if ($(".ui-selected, .ui-selecting").length > 6) {
       $(ui.selecting).removeClass("ui-selecting");
     }
   }
});​


Working Fiddle

参考:selecting event

09-18 16:49