怎样用一个已有的jquery对象得到其他的子元素?

How could I get the sub element by using an existed jQuery object ?
已经有了#divTest的对象,怎样通过它来得到其他的元素?

    <!doctype html>

    <html>

    

    <head>

        <meta charset="utf-8">

        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

    </head>

    

    <body>

    

        <div id="divTest">

            <input type="text" value="a" />

            <input id="next" type="text" value="b" />

            <input type="text" value="c" />

            <input type="text" title="d" value="d" />

            <input type="checkbox" title="e" />

    

        </div>

    

        <script>

            var myObj = $("#divTest");

            //How could I get the checkbox element by using 'myObj'?

            

            //解决办法:

            var titlevalue = myObj.children("input[type='checkbox']").attr("title");

        console.log(titlevalue);

            

        </script>

    

    </body>

    

    </html>


慕容森
浏览 551回答 1
1回答

喵喔喔

子元素用 children 方法,后代元素用 find 方法
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript