代码之家  ›  专栏  ›  技术社区  ›  Tehrab

jQuery LI删除在IE8中失败

  •  0
  • Tehrab  · 技术社区  · 16 年前

    我有一个简单的ASP.Net表单,其中包含以下无序列表:

    <ul id="ctl00_ContentPlaceHolder1_BulletedList1">
        <li>No Lines Added</li>
    </ul>
    

    当一个用户开始填写表单的其他部分时,我想删除这一部分 <LI> 开始在列表中填充其他 <LI> 元素。下面的代码是我如何删除的:

    function commitLine() {
        //if "No Lines Added" is the only item, remove all items, otherwise
        //continue with the additional item
        if ($("#ctl00_ContentPlaceHolder1_BulletedList1 li:nth-child(1)").text() == "No Lines Added") {
            $("#ctl00_ContentPlaceHolder1_BulletedList1 li").remove();
        }
        //code that begins the list population
    }
    

    3 回复  |  直到 16 年前
        1
  •  1
  •   x1a4    16 年前

    是 $("#ctl00_ContentPlaceHolder1_BulletedList1 li:nth-child(1)").text() 返回IE中被空格包围的文本?如果是的话,把这个片段改成 $.trim($("#ctl00_ContentPlaceHolder1_BulletedList1 li:nth-child(1)").text()) 移除它。

        3
  •  0
  •   DS.    16 年前

    我添加了两行代码,您的代码运行良好:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=8">
    </head>
    
    推荐文章