简体   繁体   English

选择极限

[英]selectable limit

am trying to add limit of 6 selectable rows but i can't make it work. 我试图添加6个可选行的限制,但我无法使其工作。 Any help!! 任何帮助!!

<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>

I amtrying to add this source code below into the one above 我试图将下面的源代码添加到上面的源代码中

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

Anyone?? 任何人?? Thanks 谢谢

$("#selectable").selectable({
    filter: 'li:lt(4)',
    selecting: function(event, ui) {
        $('ui.selecting')
        $('.ui-selecting:gt(3)').removeClass("ui-selecting");
    }
});

For more about :lt() , here 有关:lt()更多信息,请点击这里

You don't give your html code in post. 您不要在发布后提供html代码。 but you can try this: 但您可以尝试以下操作:

 filter: "table.selectable > tr > td.cs:lt(4)"

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM