2010-07-07 51 views
0

对,我创建了一个使用jquery的插件,到目前为止我所拥有的就是这个。 。与JQuery插件相关。 。从一个对象获取数组元素

(function ($) { 

$.fn.AppCompFunctionality = function() { 
    var defaults = { 

}; 

var options = $.extend(defaults, options); 
return this.each(function() { 

    $(this).click(function() { 
     var currentComps = $("#currentComps").get(); 
     $(currentComps).hide(); 
}); 
}); 

}; 

})(jQuery); 

现在假设currentComps是具有列表项的无序列表中说

<ul id="currentComps"> 
<li id="CompName"> 
Component Name: 
</li> 
<li id="CompVersion"> 
Component Version: 
</li> 
</ul> 

我想用id列表项说“COMPNAME”而已,如何将我通过检索该插入。 。通过currentComps作为完整的对象,我得到 -

我不希望能够选择CompName使用eq()要么能够选择是通过它的id,但通过CurrentComps,如果这是有道理的。

回答

0

你能做到几个方面:

$("#currentComps").children().each(function() { 
    if (this.id == "CompName") 
    alert("CompName"); 
}); 

$("ul#currentComps li#CompName") 
+0

随着plugings虽然我有 '得' 的所有使用GET方法数组元素。 。当我尝试这些技巧时,不要认为它有效。 – Calibre2010 2010-07-07 16:12:25