2013-03-11 44 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