我正在尝试获取子li元素的ID,并查看该ID是否包含单词“ unit”。这是我一直在研究的javascript部分:
insertSearchIcon: function(evt){
var treeExists = $( '.jstree-icon' ).html();
var currentTarget = $(evt.currentTarget);
if (treeExists != null){ //Check to see if tree exists
var elementExists = document.getElementsByClassName( 'oob-dropdown' );
zero = 0;
if(elementExists.length == zero){ //Check to see if button is already there
var idOfParent = currentTarget.siblings('li').id;
if(idOfParent.indexOf("unit") != -1){ //Check to see if element is not a unit
currentTarget.$( '.jstree-leaf' ).prepend('<button class="oob-dropdown" id="oob-button"></button>');
}
}
}
}
我试图获取与单击的“ .jstree-icon”下的“ .jstree-leaf”一起的ID:
<li id="unit-27404752" class="jstree-last jstree-open">
<ins class="jstree-icon"> </ins><!--this one was clicked-->
<a href="#">
<ul style="">
<li id="unit-27404753" class="jstree-closed">
<li id="unit-27404754" class="jstree-closed">
<li id="unit-27404755" class="jstree-leaf">
<ins class="jstree-icon"> </ins> <--!Not this one>
<a class="" href="#">
<ins class="jstree-icon" style="background: url("/api/mil2525/images/SFGPUUM----CUSG") no-repeat scroll center center transparent;"> </ins>
S2 SEC 330 MED
</a>
在我按期望的方式工作之后,此功能即会工作,感谢所有帮助。
insertSearchIcon: function(evt){
var treeExists = $( '.jstree-icon' ).html();
var currentTarget = $(evt.currentTarget);
if (treeExists != null){ //Check to see if tree exists
var elementExists = document.getElementsByClassName( 'oob-dropdown' );
zero = 0;
if(elementExists.length == zero){ //Check to see if button is already there
$('.jstree-leaf').each(function(){ //If not a unit put button
var id = this.id;
if (id.indexOf("unit") == -1){
$(this).prepend('<button class="oob-dropdown" id="oob-button"></button>');
}
});
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句