浅谈js控制li标签排序问题 js调用php函数的方法
【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>
相关推荐
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10