我仍在尝试使用follwoing脚本和html将已排序的ul(使用sortablejs ui)中的项目转换为字符串:
<script>
$(function makeSort() {
$( "#description" ).sortable({
});
$( "#description" ).disableSelection();
});
function getOrder() {
var ans = $('#description').text().replace(/[\r\n|\n|\r]/gm, " ");
alert("You got " + ans)
};
</script>
</head>
<body>
<ul id = "description">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<script>
var Final = $('#description').text().replace(/(\r\n|\n|\r)/gm," ");
document.write('this script gives from the above list: ' + Final);
</script>
<button onclick="getOrder();">Check</button>
</body>
我无法获得按钮功能(变量ans)以给出word1空格word2空格word3的正确格式,而var Final给出正确的一二三。我以为可排序的js只是重新排列了
<ul>
<li>item1</li>
<li>item2</li>
</ul
排序后会变成
<ul>
<li>item2</li>
<li>item1</li>
<ul>
,这样两个函数应该给出相同的答案?感谢对此的任何帮助