jquery字符串转dom对象及对该对象使用选择器查询

12/6/2015来源:Javascript教程人气:1163

<script>
    $(document).ready(function () {
        var htmlStr = '<div id="outerDiv"><div class="class1"><a>aa</a></div><div class="class1"><span>bb</span></div><div>cc</div></div>'
        var htmlObj = $(htmlStr); //将字符串转为jquery的dom对象
        console.log(htmlObj.html());

        var filterObj = htmlObj.find(".class1"); //对转换后的对象进行查询
        console.log(filterObj);
        alert($(filterObj[0]).html()); //<a>aa</a>
        alert($(filterObj[1]).html()); //<span>bb</span>
    }); 
</script>

 

原文地址: http://www.cnblogs.com/xuejianxiyang/p/4960042.html