0

我想将父 DOM 节点类添加到其子 dom 中,

例如让我们说,

<ol class="test1">
        <li>
        <li>
           <ol>

我想对孩子说 ol 以获取其父级 ol 中的所有课程。

4

2 回答 2

0
$('li').attr('class', function() {
    return $(this).closest('ol').attr('class');
});

或者没有 jQuery:

var lis = document.getElementsByTagName('li');

for (var i=lis.length; i--;) {
    lis[i].className = lis[i].parentNode.className;
}

LI 标签当然必须关闭才能正常工作

于 2013-06-25T05:45:56.727 回答
0
$(".test1").find('ol').each(function(){
    $(this).attr("class",$(".test1").attr('class'));
    });
});
于 2013-06-25T05:50:12.333 回答