我正在使用jquery校验树插件,它工作得很好。在这种情况下,我希望以编程方式展开某些节点。
我看到我可以通过Id来完成,如示例中所示:
$('#tabs-5-expand').click(function(){
$('#tree5').checkboxTree('expand', $('#tabs-5-node23'));
}); 我希望我可以使用这样的类名来扩展多个节点
$('#tabs-5-expand').click(function(){
$('#tree5').checkboxTree('expand', $('.bluetabs'));
}); 但它似乎什么也没做。有没有人知道是否有一种使用类选择器以编程方式展开或折叠节点的方法?
发布于 2014-09-24 10:45:04
检查一下这把小提琴并取消对处理程序的注释,每次一个。正确的方法是迭代元素的数组。请查看评论以获得更多信息。
<ul id="tree6">
<li><input type="checkbox" checked><label>Root</label>
<ul>
<li class="bluetabs"><input type="checkbox"><label>Node 1</label>
<ul>
<li><input type="checkbox"><label>Node 1.1</label></li>
</ul>
</li>
<li><input type="checkbox" checked><label>Node 2</label>
<ul>
<li><input type="checkbox"><label>Node 2.1</label></li>
<li><input type="checkbox"><label>Node 2.2</label></li>
<li class="bluetabs"><input type="checkbox"><label>Node 2.3</label>
<ul>
<li><input type="checkbox"><label>Node 2.3.1</label></li>
<li><input type="checkbox"><label>Node 2.3.2</label></li>
</ul>
</li>
<li><input type="checkbox"><label>Node 2.4</label></li>
<li><input type="checkbox"><label>Node 2.5</label></li>
<li><input type="checkbox"><label>Node 2.6</label></li>
</ul>
</li>
</ul>
</li>
</ul>
<button id="test">Press to expand</button>
$('#tree6').checkboxTree({
initializeChecked: 'expanded',
initializeUnchecked: 'collapsed'
});
//If all the bluetabs are collapsed this will work. If you expand one of the blue ones, then it won't work for the other.
$('#test').click(function() {
$('#tree6').checkboxTree( 'expand', $('.bluetabs') );
});
//This will work regardless
$('#test').click(function() {
$('.bluetabs').each(function() {
$('#tree6').checkboxTree( 'expand', $(this) );
});
});https://stackoverflow.com/questions/25880911
复制相似问题