【Html代碼】
<span style="font-size:14px;"><ul class="list-group"> <? if ($categorys): ?> <? foreach ($categorys as $category):?> <li class="list-group-item" data-id="<? echo $category->id ?>"> <? echo $category->name?> <a href="<? echo site_url('group/category/delete?id=' . $category->id) ?>" onclick="<?echo lang('confirm')?>"> <span class="glyphicon glyphicon-remove"></span></a> </li> <? endforeach;?> <? else: ?> <div class="alert alert-danger">暫時沒有設置</div> <? endif; ?> </ul></span>
【js代碼】
<span style="font-size:14px;"> <script> require(["jquery","jqueryui"],function($) { var d = window.top.dialog({ content: '配置已更新' }); $(function() { $( ".list-group").sortable({ stop: function( event, ui ) { data = ''; $('li.list-group-item').each(function (){ data += ',' + $(this).attr('data-id'); }); $.post('/group/category/listorder',{data:data}); d.show(); setTimeout(function () { d.close(); }, 1000); } }).disableSelection(); }); }); </script></span>
【php代碼】
<span style="font-size:14px;">public function listorder() { $data = explode(',', $this->input->post('data')); $i = 1; foreach ($data as $id) { if (!$id) continue; $this->category_model->save($id, array( 'listorder' => $i, )); $i++; } } public function delete() { $id = $this->input->get('id'); $this->category_model->delete($id); messagebox(lang('success'), 'referer'); }</span>
以上就是小編為大家帶來的淺談js控制li標簽排序問題 js調用php函數的方法全部內容了,希望大家多多支持~