我们有时候知道UL的id,但是苦不堪言的找不到LI进行清除,这边有一些办法可以参考,设置Li的id是不错的方法,但是千万别设置成一个ID,到时候删除只会删除第一个
可以使用
- $("#ul li").not(":first").remove();
我这边是用:
- $(document).ready(function(){
- $("#search_content").keyup(function () {
- if(CheckChinese($("#search_content").val()))
- {
- $.ajax({
- type: "POST",
- anync: true,
- url: "HelpCenterSuggestion.ashx",
- cache: false,
- dataType: "text",
- data: { m: $("#search_content").val() },
- success: function (result) {
- alert(result);
- $("#UlContent li").remove();
- $("#UlContent").append(result);
- }
- });
- }
- });
方法很多,还可以用:
- 1、用not
- $("ul>li").not(":eq(0)").remove();
- 或
- $("ul>li").not(":first").remove();
- 2、用filter
- $("ul>li").filter(function(index){
- return index!=0;
- }).remove();