2012-06-13 6 views
0

제한을 선택하도록이 선택 가능한 스크립트를 만들려고합니다. 나는 선택의 제한 4.선택 가능한 제한 스톱

http://jsfiddle.net/dw6Hf/51/

$(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); 
     } 
    }); 
});​ 

이 하나가 당신을 제공해야합니다 내가 요구 사항을 이해하는 것이 지금 당신에게

+0

왜 '길이 * 2'가 선택 항목을 두 번 출력 할 수 있습니까? – AbstractChaos

+0

나는 몇 가지 것을 시도했다 !! 내가 원하는 것은 4를 선택하고 상자를 선택하는 것을 멈추는 것입니다. 어떻게 할 생각인가? – user1421432

+0

나는이 스크립트를 사용하여 내가 필요로하는 것을 가장 잘 할 수있다. 그것을 추가 할 뜨거운 바이올린에 내게 보여줄 수있다 – user1421432

답변

0

확인 감사 인 제한 번호를 넘어 때 선택을 중지하려면 네가 요구 한 것. 정지에서 선택 가능으로 변경한다는 것은 정지가 시작된 이후가 아니라 "선택"되기 전에 결정할 수 있음을 의미합니다.

fiddle

+0

제 질문은 : 더 많은 tham 4를 선택할 때 상자 선택을 중단 할 수 있습니까? – user1421432

+0

좋아, 나는 사실을 후 간단하게 제거하고 싶다고 생각했다. 나의 실수는 이것을 반영하기 위해 나의 대답을 편집했다. – AbstractChaos

0

이이 같은 this

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

중복

편집 뭔가를 작동?

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

     // do not allow selecting more than four items 
     selecting: function(event, ui) { 
      if ($(".ui-selected, .ui-selecting").length > 4) { 
       $(ui.selecting).removeClass("ui-selecting"); 
      } 
     }    

     // do whatever you like with the selected 
     stop: function() { 
      var result = $("#select-result").empty(); 
      var result2 = $("#result2");    

      $('#divmsg').html($(".ui-selected").length*2+ " box selected") 

      $(".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); 
     } 
    }); 
});? 
+0

전에 본 적이 있지만 스크립트에 추가하여 작동하도록 할 수 있습니다! 당신이 나를 도와 줄 수 – user1421432

+0

특정 스크립트 – Elad

+0

편집 EDIT 추가 할 수없는 경우 문제를 자세히 설명하십시오. – Elad