目前我已经写了一个表格,里面有单独的有序列表。然而问题是当我使用 jquery 来获取索引时,我得到的是一个连续数字的索引。我希望有人能够帮助我将每个有序列表的这个数字重新恢复为 1。我试过了,但没有用。下面提到的是我的代码。提前致谢
<tr>
<td>
<ol start="1" class="selectable">
<li class="ui-widget-content">0800 - 0830</li>
<li class="ui-widget-content">0830 - 0900</li>
</ol>
</td>
<td>
<ol start="1" class="selectable">
<li class="ui-widget-content">0800 - 0830</li>
<li class="ui-widget-content">0830 - 0900</li>
</ol>
</td>
<script>
$(function() {
$( ".selectable" ).selectable({
stop: function() {
$(".selectable li").css({"background":"white","color":"black"});
var result = $( "#select-result" ).empty();
var bookingHours = $( "#booking-hours" ).empty();
var bookingPeriod = [];
var count = 0;
$( ".ui-selected", this ).each(
function() {
$( this ).css({"background":"#F39814","color":"white"});
var index = $( ".selectable li" ).index( this )+1;
bookingPeriod[count] = index;
count++;
}
);
bookingHours.append( (count*0.5) + " Hours" );
var bookingFrom = bookingPeriod[0];
var bookingTo = bookingPeriod[bookingPeriod.length-1];
result.append( ( bookingFrom ) + " to " + ( bookingTo ) );
}
});
});
</script>