怎样操作序号,让前标为顺序的!
拖曳排序之后,怎样操作让前标号为顺序的?(注:忽略(li)标签里面的文本标签!)
2017-03-17
<ul>
<li><span>1</span>)足球</li>
<li><span>2</span>)散步</li>
<li><span>3</span>)篮球</li>
<li><span>4</span>)乒乓球</li>
<li><span>5</span>)骑自行车</li>
</ul>
<script type="text/javascript">
$(function () {
$("ul").sortable({
delay : 2,
opacity : 0.35,
stop:function(){
$("li>span").each(function(index){
$(this).html(++index);
})
}
})
});
</script>
each()里函数有个参数代表span集合中当前元素的下标(从0开始)的,所以直接用这个++index就好了
<div class="content"> <ul> <li><span>1</span>足球</li> <li><span>2</span>散步</li> <li><span>3</span>篮球</li> <li><span>4</span>乒乓球</li> <li><span>5</span>骑自行车</li> </ul> </div> </div> <script type="text/javascript"> $(function () { $("ul").sortable({ delay:3, opacity:0.35, stop:function(index){ var index=0; $('li>span').each(function(){ $(this).html(++index); }) } }) }); </script>
举报