<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p id="pp" title="选择你喜欢的水果">你最喜欢的水果是?</p>
<ul>
<li title="苹果">苹果</li>
<li title="橘子">橘子</li>
<li title="菠萝">菠萝</li>
</ul>
<button type="btn">增加一个li元素</button>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).on("click","button",function () {
<!-- 动态增加元素 -->
var li_len=$("ul li").length+1;
var add_info=$("<li title='ss' "+">"+ li_len +"</li>");
$("ul li:last").after(add_info);
});
</script>
</body>
</html>
网友评论