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

查看:63
本文介绍了javascript - 怎样用一个已有的jquery对象得到其他的子元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

    <!doctype html>
    <html lang="en">
    
    <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>

解决方案

子元素用 children 方法,后代元素用 find 方法

这篇关于javascript - 怎样用一个已有的jquery对象得到其他的子元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆