在 HTML 中创建嵌套有序列表时,嵌套元素通常会从 1 开始重新编号。要实现连续编号,请执行以下操作这些步骤:
CSS 方法(对于现代浏览器)
html>/**/body ol { list-style-type: none; counter-reset: level1; } ol li:before { content: counter(level1) ". "; counter-increment: level1; } ol li ol { list-style-type: none; counter-reset: level2; } ol li ol li:before { content: counter(level1) "." counter(level2) " "; counter-increment: level2; }
jQuery Approach (for IE6/7)
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
$(document).ready(function() { if ($('ol:first').css('list-style-type') != 'none') { $('ol ol').each(function(i, ol) { ol = $(ol); var level1 = ol.closest('li').index() + 1; ol.children('li').each(function(i, li) { li = $(li); var level2 = level1 + '.' + (li.index() + 1); li.prepend('<span>' + level2 + '</span>'); }); }); } });
以上是如何在HTML中实现嵌套有序列表的连续编号?的详细内容。更多信息请关注PHP中文网其他相关文章!