如何使用jquery 的方法,将一段ul内a的title都一样的li去掉。
代码部分<ulclass="list-group"><liclass="list-group-item"><atitle="AcademicWriting">Academ...
代码部分
<ul class="list-group">
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
</ul>
效果如图: 展开
<ul class="list-group">
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
</ul>
效果如图: 展开
展开全部
$('ul li').not(function (i) {
return $(this).prevAll('li:has(a[title="' + $('a', this).attr('title') + '"])').length < 1;
}).remove();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jQuery(function($) {
$("ul li a").each(function(i, dom) {
var me = $(dom),
t = me.attr("title");
var ind = me.closest("li").index();
$("ul li:gt(" + ind + "):has(a[title='" + t + "'])").remove();
});
});
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-09-22
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script language="javascript">
$(document).ready(function () {
for(var i=0;i<$(".list-group").find("li").length;i++){
var obj=$(".list-group").find("li").eq(i).find("a").attr("title");
for(var j=i;j<$(".list-group").find("li").length;j++){
var cur=$(".list-group").find("li").eq(j).find("a").attr("title");
if(obj==cur){
$(".list-group").find("li").eq(j).remove();
}
}
}
});
</script>
</head>
<body>
<ul class="list-group">
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
</ul>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script language="javascript">
$(document).ready(function () {
for(var i=0;i<$(".list-group").find("li").length;i++){
var obj=$(".list-group").find("li").eq(i).find("a").attr("title");
for(var j=i;j<$(".list-group").find("li").length;j++){
var cur=$(".list-group").find("li").eq(j).find("a").attr("title");
if(obj==cur){
$(".list-group").find("li").eq(j).remove();
}
}
}
});
</script>
</head>
<body>
<ul class="list-group">
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Oral Presentation">Oral Presentation</a></li>
<li class="list-group-item"><a title="Academic Writing">Academic Writing</a></li>
</ul>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询