2013-05-01 2 views
3

javascript 또는 jquery를 사용하여 특정 삭제 된 태그를 가져 오는 방법. 내가 선택 요소에서 모두를 선택하고 난 그냥 바로 여기에 삭제 된 태그를 얻으려면 내가 서버 측의 태그를 오토넷하고 array_diff 사용하고하는 것은Jquery Select2 tags

<script> 
      $(document).ready(function(){ 
       $("#e23").select2({ 
        tags:[], 
        dropdownCss: {display: 'none'}, 
        tokenSeparators: [" "], 
        maximumInputLength: 10 
        }); 
      var x =$("#e23").val(); 
      $("#e23").on("change", function() {var as=($("#e23").val()); 
      $.ajax({ 
       url: "http://localhost/healthkatta/index.php?r=jdashboard/Demo/create",//this is the request page of ajax 
       data: { 
        //special:specialisation, 
        name1 :x, 
        name2 :as, 
       },//data for throwing the expected url 
       type:"GET",//you can also use GET method 
       dataType:"html",//you can also specify for the result for json or xml 
       success:function(response){ 
         $('.log').html(response); 
       }, 
       error:function(){ 
        //TODO: Display in the poll tr ifself on error 
        alert("Failed request data from ajax page"); 
       } 
      });}); 
       }); 
     </script> 

    <body> 


    <strong>Default Keywords</strong> 
    <br> 
    <br> 
    <div class="log"></div> 
    <input id="e23" class="select2-offscreen" type="hidden" value="<?php for($i=0;$i<count($result);$i++){ 
     if ($i == count($result)-1) 
      echo $result[$i]->keyword->keyword;  
     else 
      echo $result[$i]->keyword->keyword.','; 
    }?>"style="width:500px" tabindex="-1"> 
    <div id="dialog-form" title="Add Custom Keywords"> 
    <form> 
     <fieldset> 
     <label for="name">Keyword</label> 
     <input type="hidden" name="name" id="name" class="text ui-widget-content ui-corner-all" /> 
    </fieldset> 
    </form> 
    </div> 
    <br> 
    <br> 
    <button id="create-user">Add More</button> 

    </body> 

답변

3

.on("change", function(e) { 
    if(typeof e.added != 'undefined'){ 
     // ID OF ADDED ELEMENT 
     var added_id = e.added.id; 
    }else if(typeof e.removed != 'undefined'){ 
     // ID OF REMOVED ELEMENT 
     var removed_id = e.removed.id; 
    } 
}); 
+0

감사 같은 것을 시도 내 코드입니다 회신을 위해 @rajesh kakawat 그것을 시도하십시오 – Ninad

+0

@rajesh kakawat 코드가 작동 감사합니다 – Ninad