我正在使用Dragula进行一些排序和排序,但是我需要将新的订单值放入数组中以通过PHP保存。
我正在通过JQuery或Javascript使用它。
<div id="right-events" class="containerdrag">
<div id="drag0" class="w-100 border border-primary rounded p-2 ex-moved">choice1</div>
<div id="drag3" class="w-100 border border-primary rounded p-2 ex-moved">choice4</div>
<div id="drag4" class="w-100 border border-primary rounded p-2 ex-moved">choice5</div>
<div id="drag1" class="w-100 border border-primary rounded p-2 ex-moved">choice2</div>
<div id="drag2" class="w-100 border border-primary rounded p-2 ex-moved">choice3</div>
</div>
我正在尝试输出这样的数组:
$array = ("choice1","choice4","choice5","choice2","choice3");
答案 0 :(得分:0)
您可以使用map
和get
jquery方法获取文本值数组。
$("#save").click(function() {
const data = $('#right-events > div').map(function() {
return $(this).text()
}).get()
console.log(data)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="right-events" class="containerdrag">
<div id="drag0" class="w-100 border border-primary rounded p-2 ex-moved">choice1</div>
<div id="drag3" class="w-100 border border-primary rounded p-2 ex-moved">choice4</div>
<div id="drag4" class="w-100 border border-primary rounded p-2 ex-moved">choice5</div>
<div id="drag1" class="w-100 border border-primary rounded p-2 ex-moved">choice2</div>
<div id="drag2" class="w-100 border border-primary rounded p-2 ex-moved">choice3</div>
</div>
<button id="save">Save</button>