您的示例在 IE 中对我不起作用,您必须在文档中指定Doctype 标题才能在 IE 中以标准方式呈现您的页面,以使用 content CSS 属性:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<html>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
</html>
第二种方法是使用 CSS 3 选择器
li:not(:last-of-type):after
{
content: " |";
}
但是你仍然需要指定 Doctype
第三种方法是使用带有一些脚本的 JQuery,如下所示:
<script type="text/javascript" src="jquery-1.4.1.js"></script>
<link href="style2.css" rel="stylesheet" type="text/css">
</head>
<html>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
<script type="text/javascript">
$(document).ready(function () {
$("li:not(:last)").append(" | ");
});
</script>
第三种方式的优点是您不必指定 doctype 并且 jQuery 将负责兼容性。