2013-03-11 48 views
-1

我試圖做的是將li元素從一個容器移動到另一個容器上。我有一個選擇和我的選擇容器,如果用戶從第一個容器中點擊li span(id =「add」),則li將被移除,並應出現在第二個容器中。 比我想出以下結構,也許不是最好的解決方法,因爲我有問題只移動選定的李,我真的不知道如何處理在這種情況下的回調。我會很感激的建議li在jquery上選擇的問題

<script> 
(function($){ 
jQuery("#catalog").accordion({ 
heightStyle: "content" 
}); 

jQuery("span#add").click(function(){ 
    jQuery(this).parent().animate(
      { 
       'margin-left':'1000px' 
      },1000, 
      function(){ 
       var ul_class = $(this).parent().attr('class'); 
       $(this).slideUp('fast');    
       $("ul."+ ul_class + "_clone").append($(this).parent().html()); 
       $(this).remove();     
      } 
      ); 

}); 

}) (jQuery); 
</script> 

<?php $datas = json_decode($param[0]->params) ?> 
<div class="config_holder"> 
<div id="products"> 
    <h3>Config Params</h3> 
    <div id="catalog"> 
     <?php foreach ($datas as $key1=>$data):?> 
      <h4><a href="#"><?php if(!empty($key1)) echo $key1 ?></a></h4> 
     <div> 
      <ul class="<?php echo $key1 ?>"> 
       <?php if(!empty($data)):?> 
       <?php foreach($data as $key2=>$item):?> 
       <?php if($key2 !="&nbsp;" || $key2 != " "): ?> 
       <li id="" class="ui-state-default ui-corner-all" ><?php echo $key2; ?><span style="float:right" id="add" class="ui-icon ui-icon-circle-plus"></span></li> 
       <?php endif;?> 
       <?php endforeach; ?>     
       <?php endif;?> 
      </ul> 
     </div> 
     <?php endforeach;?> 
    </div> 
</div> 
<div id="cart"> 
<h3 >Mein Konfiguration</h3> 
<div class="ui-widget-content"> 
<img title="" src="http://i.dell.com/das/dih.ashx/165x130/sites/imagecontent/consumer/merchandizing/de/PublishingImages/165x119/6315-inspiron-17r-5721-165X119-de.png" alt=""> 
<ol> 
<li class="placeholder">My Choises</li> 
<?php foreach ($datas as $key3=>$clone):?> 
<ul class="<?php echo $key3 ?>_clone"></ul> 
<?php endforeach;?> 

</ol> 

</div> 
<a href=""><button>search</button></a> 
</div> 
</div> 
+0

可能只是你的措辭,但'變種的方式ul_class = $(this).parent()。attr('id');'是一個id而不是類(編輯:這是編輯出來的) – DickieBoy 2013-03-11 14:26:05

+2

建議:你不應該有超過1個元素具有相同的id。 Id在整個頁面中應該是唯一的。 – Jamiec 2013-03-11 14:26:11

+1

嘗試將jQuery(「span#add.ui-icon」)更改爲jQuery(「span#add_icon」) – 2013-03-11 14:27:14

回答

0

如果你可以使用jQuery的UI你可以使用其連接列表的能力。

$(function() { 
    $("#IdOfFirstList, #IdOfSecondList").sortable({ 
     connectWith: ".commonClassName" 
    }).disableSelection(); 
}); 

繼承人是鏈接到完整的例子http://jqueryui.com/sortable/#connect-lists

+0

謝謝我要試一試! – fefe 2013-03-11 14:46:46

0

嘗試......

$("span, #add, .ui-icon").on('click', function(){ 
    $(this).parent().animate({'margin-left':'1000px'}, 1000, function(){ 
     var ul_class = $(this).parent().attr('id'); 
     $(this).slideUp('fast');    
     $("ul#"+ ul_class + "_clone").append($(this).parent().html()); 
     $(this).remove(); 
    }); 
}); 

而且看到這個DEMO