js获取子节点的方法

JavaScript013

js获取子节点的方法,第1张

你的oLi是所有li的集合,所以你使用oLi的时候应该加下标,才能表示你使用的 是 哪个li

所以

var oDiv = oLi[此处是下标].getElementsByTagName('div')

$(function () {

    $(".navbar-inverse li").each(function (index) {

        if ($(this).children().text().indexOf("主页") >= 0) {

            $(this).addClass("active")

        }

    })

})

这个是获取ul下的li,然后设置样式。

我试过了,有作用的,你要么就委派事件,如果还不可以的话,delegate知道吧???

<!DOCTYPE HTML>

<html>

<head>

<meta charset=UTF-8>

<meta name="keywords" content="白菜编辑部">

<title>白菜编辑部</title>

<style type="text/css">

</style>

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

<script type="text/javascript">

jQuery (function ($)

    {

    $ ('body').append ('<div class="out"><a>.....</a><h1>......</h1><div class="btn">btnbtnbtn</div></div>')

    $ ('div.out').mouseover (function ()

    {

    $ ('.btn').show ()

    }).mouseout (function ()

    {

    $ ('.btn').hide ()

    })

    })

</script>

</head>

<body>

</body>

</html>