0

我有一些想法,我对这段代码有点困惑:这行代码是我想知道的:

var items = $("#" + element[0].id + " li");

现在我的问题是:这行代码是如何工作的?那么这里的魔力在哪里?它是否填充了项目数组?

顺便谢谢!

当我们针对<ul> - 元素时,jquery 是否会一步到位?(使用此代码:

 $(document).ready(function() {
            $("#slider").mySlider({
                timeOut: 4000,
                captionOpacity: .7            
            });  

这是代码的一部分,我想知道的部分:假设你有这个 html

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

<script src="js/mySlider.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#slider").mySlider({
            timeOut: 4000,
            captionOpacity: .7            
        });
    });
</script>
<title></title>
</head>
<body>

    <ul id="slider">
        <li>
            <img src="img/image1.jpg" alt="" />
            <div class="top">
                Some nice text captions..
            </div>
        </li>
        <li>
            <img src="img/image2.jpg" alt="" />
            <div class="bottom">
                Some nice text captions..
            </div>
        </li>

    </ul>

</body>
</html>

这里是JS:

  $.fn.mySlider   = function(vars) {

        var timeOut     = vars.timeOut || 4000;
        var capOpacity  = vars.captionOpacity || .7;
        var element     = this;
        var fxDuration  = timeOut/6;

        var items       = $("#" + element[0].id + " li"); //how do add the < li > items inside this array?
        var captions    = $("#" + element[0].id + " li div");
       // console.log(items);
        items.css('display','none');

        captions.css({
            'opacity': capOpacity,
            'display': 'none'
        });
4

1 回答 1

0

如果你想要你的 LI 元素的“孩子”,你可以使用:

var items = $("#" + element[0].id + " li").children();

.children(optFilter)上的 jQuery 文档

使用过滤器,您可以选择指定只需要DIVs 或As。

例如

$("#" + element[0].id + " li").children("div");//just the <div>s
$("#" + element[0].id + " li").children("a");//just the <a>s
于 2013-09-16T14:32:44.257 回答