【问题标题】:Hide the span with a class name jquery使用类名 jquery 隐藏跨度
【发布时间】:2012-04-08 14:51:14
【问题描述】:

隐藏具有特定类名的跨度时,我被困在该怎么做。我不能使用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 是否包含具有类名的任何子级。如果是这样,请将其隐藏。

我从这里去哪里?我确信这个答案是显而易见的,但我只是没有看到它。

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    像这样将类名连接到选择器

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

    【讨论】:

    • 呃。好一个。非常感谢!
    【解决方案2】:

    试试这个

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

    【讨论】:

      【解决方案3】:
      $('.classname').hide();
      $('.' + classnameasvariable).hide()
      

      【讨论】:

        猜你喜欢
        • 2012-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-11
        • 1970-01-01
        • 1970-01-01
        • 2013-08-07
        相关资源
        最近更新 更多