gpt4 book ai didi

php - 在同一个表中保存多个 JQuery Sortable

转载 作者:行者123 更新时间:2023-12-01 05:22:49 24 4
gpt4 key购买 nike

我有多个 Ul,可以在其中拖放 li 元素:

<div class="outer-box">
<div class="header text-center">
<h4 class="title">Curriculum</h4>
<p class="category">Start putting together your course by creating sections, lectures and practice quizzes below.</p>
</div>
<div class="inner-box">
<div class="header">
<h4 class="title text-left">Section 1:</h4>
<div class=" header text-left">
<ul class="sortable ui-sortable" style="list-style-type: none;">


<li class="lecture ui-sortable-handle">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 3: Testing</small></p>
</li><li class="lecture ui-sortable-handle">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 1: Testing</small></p>
</li><li class="lecture ui-sortable-handle">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 2: Testing</small></p>
</li>


</ul>
</div>
</div>
</div>

<div class="inner-box">
<div class="header">
<h4 class="title text-left">Section 2:</h4>
<div class=" header text-left">
<ul class="sortable ui-sortable" style="list-style-type: none;">

<li class="lecture ui-sortable-handle">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 5: fasd</small></p>
</li>
</ul>
</div>
</div>
</div>
<div class="inner-box">
<div class="header">
<h4 class="title text-left">Section 3:</h4>
<div class=" header text-left">
<ul class="sortable ui-sortable" style="list-style-type: none;">

<li class="lecture ui-sortable-handle">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 4: asdf</small></p>
</li>
</ul>

让其在多个 Ul 之间拖放的脚本是

<script type="text/javascript">
$('.sortable').sortable({
connectWith: '.sortable',
revert: true
});
</script>

输出类似于: enter image description here

基本上,我试图在数据库中保存它的节号和讲座号。

例如:

section_id | lecture_id | 

1 3
1 1
1 2
2 5
3 4

这样当我加载时,它会按照保存的顺序加载。

我无法应用ajax来保存这种结构。

谢谢。

最佳答案

我创建了一个DEMO这里。看看吧。

请注意:我已经给 id发送至<ul><li> s

这是代码:

JS:

$('.sortable').sortable({
connectWith: '.sortable',
revert: true
});

$('#btn').click(function() {
var arr = [];
$.each( $("ul.sortable"), function( index, value ) {
var sortedIDs = $( this ).sortable( "toArray" );
var sectionId = $(this).attr('id');
arr[index] = [];
arr[index]['sectionId'] = sectionId;
arr[index]['sortedIDs'] = sortedIDs;
//console.log(sortedIDs);
})
console.log(arr);
alert(arr.serializeArray())
});

HTML:

<div class="outer-box">
<div class="header text-center">
<h4 class="title">Curriculum</h4>
<p class="category">Start putting together your course by creating sections, lectures and practice quizzes below.</p>
</div>
<div class="inner-box">
<div class="header">
<h4 class="title text-left">Section 1:</h4>
<div class=" header text-left">
<ul class="sortable ui-sortable" style="list-style-type: none;" id="sec1">


<li class="lecture ui-sortable-handle" id="lec3">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 3: Testing</small></p>
</li>

<li class="lecture ui-sortable-handle" id="lec1">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 1: Testing</small></p>
</li>

<li class="lecture ui-sortable-handle" id="lec2">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 2: Testing</small></p>
</li>


</ul>
</div>
</div>
</div>

<div class="inner-box">
<div class="header">
<h4 class="title text-left">Section 2:</h4>
<div class=" header text-left">
<ul class="sortable ui-sortable" style="list-style-type: none;" id="sec2">

<li class="lecture ui-sortable-handle" id="lec5">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 5: fasd</small></p>
</li>
</ul>
</div>
</div>
</div>
<div class="inner-box">
<div class="header">
<h4 class="title text-left">Section 3:</h4>
<div class=" header text-left">
<ul class="sortable ui-sortable" style="list-style-type: none;" id="sec3">

<li class="lecture ui-sortable-handle" id="lec4">
<p><small><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color: #17AA1C;"></span> Lecture 4: asdf</small></p>
</li>
</ul>

<br><br>
<input type="button" value="Get IDs" id="btn"/>

关于php - 在同一个表中保存多个 JQuery Sortable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41917607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com