隐藏具有特定类名的跨度时,我不知道该怎么做。我不能使用 this
因为它指的是输入。这是我的脚本:
//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 是否包含任何具有类名的子项。如果是,请将其隐藏。
我从这里去哪里?我确信这个答案是显而易见的,但我只是没有看到。
最佳答案
像这样将类名连接到选择器
$("span."+className).hide();
关于javascript - 使用类名 jquery 隐藏跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9849464/