HTML利用JS移除指定的标签

JavaScript029

HTML利用JS移除指定的标签,第1张

用Js匹配li的t内容就可以的,看如下代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

</head>

<script type="text/javascript" src="jquery.js"></script>

<body>

    <div id="seltime1">

        <ul id="tbustime">

            <li t="11:00" p="60" c="50">

                <div>11:00-12:00</div>

                <div><b>50/50</b></div>

            </li>

            <li t="13:00" p="30" c="10">

                <div>13:00-13:30</div>

                <div><b>10/10</b></div>

            </li>

            <li t="13:30" p="60" c="10">

                <div>13:30-14:30</div>

                <div><b>10/10</b></div>

            </li>

        </ul>

    </div>

    <div>

<input type="button" value="移除" id="removeLi">

    </div>

</body>

<script type="text/javascript">

$(document).ready(function(){

    $('#removeLi').click(function(){

        $('#tbustime').find('li').each(function(){

            var t = $(this).attr('t')

            if(t == '13:30'){

                $(this).remove()

            }

        })

    })

})

</script>

</html>

粘贴后试试,记得引入jquery类库,若有任何疑问,欢迎追问....

function a(){<br>var inn="<li id="qwe"><span style='cursor: pointer'>删除</span></li>"<br>var div = document.getElementById("a")<br>div.innerHTML += inn<br>// 查找span<br>var span = div.getElementsByTagName('span')[0]<br>// 添加click事件<br>span.onclick = function () {<br> // 查找li,也就是父元素<br> var li = this.parentNode<br> // id属性<br> var id = li.id<br> alert(id)<br>}<br>}