2012-03-24 65 views
1

我被困在隐藏具有特定类名称的跨度时要做什么。我不能使用this,因为它指的是输入。这里是我的脚本:用类名隐藏跨度jquery

//uncheck all checkboxes 
$("input[type=checkbox]").prop("checked", false); 

$("input[type=checkbox]").each(function (index) { 
    $(this).addClass("doc" + index); 
}) 

$("input").change(function() { 

    var docName = $(this).parent().find("span"); 
    var className = $(this).attr("class"); 

if(this.checked) { 

     $("span.noneAttached").fadeOut('slow', function() { 

      docName.clone().appendTo(".attachedDocuments").addClass(className).after("<br />").text(); 

     }); 
    } 

else if (!this.checked && ($(".attachedDocuments > span").hasClass(className))) { 


    //hide the span with the class name 

} 

}); 

else if检查,看是否有复选框未被选中,如果父div包含与类名孩子。如果是这样,隐藏它。

我该从哪里出发?我相信这个答案很明显,但我只是没有看到它。

+0

和HTML是... – Tadeck 2012-03-24 05:43:48

回答

4

串联类名来选择这样

$("span."+className).hide(); 
+0

咄。好的。非常感谢! – Sethen 2012-03-24 05:46:36

0
$('.classname').hide(); 
$('.' + classnameasvariable).hide() 
1

试试这个

$(".attachedDocuments span." + classname).hide();