我想将父 DOM 节点类添加到其子 dom 中,
例如让我们说,
<ol class="test1">
<li>
<li>
<ol>
我想对孩子说 ol 以获取其父级 ol 中的所有课程。
我想将父 DOM 节点类添加到其子 dom 中,
例如让我们说,
<ol class="test1">
<li>
<li>
<ol>
我想对孩子说 ol 以获取其父级 ol 中的所有课程。
$('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 标签当然必须关闭才能正常工作
$(".test1").find('ol').each(function(){
$(this).attr("class",$(".test1").attr('class'));
});
});