0

これと非常によく似ていますが、私の場合、ラベルの値が変わる可能性があります。クリック時にフォントを変更しようとしています。ここに私がこれまでに持っているものがあります:

    // Job Type Button
    $('fieldset.workexperience input').on('change', function() {
        if ($(this).hasClass('jobtype') && ($(this).attr("name")!="")) {
            $('.'+$(this).attr("name")).toggle("slow");
            //Change color to white to show hidden
                $('label[for=$(this)]').toggleClass("hidden");

                $(this).toggleClass("hidden");

                var $this = $(this).attr("label");
                $('label[$this]').toggleClass("hidden");
        } else {

        }
    });

最初はラベルでアクセスし、2 番目は直接アクセスします (ただし、$(this) はラベルではなくチェックボックスです)。2 番目はラベルの値を取得しようとするものです。引数として渡します。

どんな助けでも大歓迎です。

ところで:CSSは:

    .hidden {
    color: white;
    }
4

1 に答える 1

2
$('label[for=$(this)]').toggleClass("hidden");

したほうがいい

$('label[for="'+ $(this).attr('id') +'"]').toggleClass("hidden");

例えば:

<label for="somecheckbox">Checkbox</label>
<input type="checkbox" id="somecheckbox">

の属性に等しいを$(this).attr('id')取得します。idlabelfor

于 2012-06-21T17:36:31.033 に答える