我正在考虑使用tinysort对复杂的div
列表进行排序
这里是第一次尝试html
<div id = "sort">
<div id = "volume">
<div id ="section1">S5
<div>S5-2</div>
<div>S5-1</div>
</div>
<div id="section2">S2</div>
<div id="section3">S3</div>
</div>
</div>
<script>
$(document).ready(function() {
tinysort('div#volume>div');
tinysort('div#section1>div');
});
</script>
我希望是
S2
S3
S5
S5-1
S5-2
不管怎样
S5
S5-2
S5-1
S2
S3
最佳答案
确保代码中包含jquery,还包括tinysort.defaults.ignoreDashes = true;
。参考下面的代码snipet
$(document).ready(function() {
tinysort.defaults.ignoreDashes = true;
tinysort('div#volume>div');
tinysort('div#section1>div');
});
<div id = "sort">
<div id = "volume">
<div id ="section1">S5
<div>S5-2</div>
<div>S5-1</div>
</div>
<div id="section2">S2</div>
<div id="section3">S3</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinysort/2.3.6/tinysort.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>