Git Product home page Git Product logo

wued-d2d-camp's People

Contributors

githuboooshy avatar lizhi334 avatar turkyden avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

wued-d2d-camp's Issues

有关 each() 方法和 index 索引值的问题

下方代码是给div添加样式并在某一个div处设置条件赋予 “return false” 来
停止循环。

问题一:为什么.each(function(i)中的i不用声明就可以使用,它是一个形参吗,为什么默认就是div的索引值?

问题二:参考代码中的domEle是一个实参吗,他和我用的$(this)有区别吗。另外我把$(this).css 改成 this.css就不行了,this取得是一个dom对象,css不就是它的 属性吗?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- jQuery (V1.11.0) -->
    <script src="/new/libs/jquery/jquery.min.js"></script>
    <style>
        div {
            width: 400px;
            background-color: aquamarine;
            height: 170px;
        }
    </style>
</head>
<body>
    <!-- <img>
    <img> -->
    <button>start</button>
    <span></span>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div id="stop" ></div>
    <div></div>
    <script>
        // $('img').each(function(i){
        //     var e = i+1
        //     this.src = '../images/img_3trends_' + e + '.png' 
        // })

        $('button').click(function(){
            $('div').each(function(i){
                $(this).css('backgroundColor','yellow');

                if($(this).is('#stop')){
                    $('span').text('Stopped at div index' + i);
                    return false;
                }
            })
        })
        
        //下方为参考代码
        // $("button").click(function () {
        //     $("div").each(function (index, domEle) {
        //         // domEle == this 
        //         $(domEle).css("backgroundColor", "yellow");
        //         if ($(this).is("#stop")) {
        //             $("span").text("Stopped at div index #" + index);
        //             return false;
        //         }
        //     });
        // });
    </script>
</body>
</html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.