【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函数的方法全部内容了,希望大家多多支持武林网~
新闻热点
疑难解答