0

フォームの読み込み時にカスタム チェックボックスの値を設定しようとしています。デバッグにより、ソースからロードされた値がチェックボックスに反映されていることがわかりますが、カスタム グラフィックは更新されません。

私の形で私は持っています

<input class="checkbox" type="checkbox" name="uitem_autorenew" id="uitem_autorenew" />

私が持っているスタイル:

    .checkbox {
        display: none;
    }

    .toggle {
        background: url("toggle.png") bottom left;
        display: block;
        width: 70px;
        height: 22px;
    }

    .toggle.checked {
        background-position: top left;
    }

コードには以下が含まれます

        $(document).ready(function() {

        $('.checkbox').after(function() {
            if ($(this).is(":checked")) {
                return "<a href='#' class='toggle checked' ref='" + $(this).attr("id") + "'></a>";
            } else {
                return "<a href='#' class='toggle' ref='" + $(this).attr("id") + "'></a>";
            }

        });

...開いているイベントを持つダイアログに...データに従ってチェックまたはチェック解除機能を確実に設定します

                var ar=$(this).data('renew');
                console.log("Value of ar = " + ar);  // which is Y

                if (ar =="Y"){
                    $("#uitem_autorenew").prop('checked',true);  // tried this 
                    $("#uitem_autorenew").toggleClass("checked");   //tried this too


                }

                console.log ("Is checkbox checked?");
                console.log ($("#uitem_autorenew").prop('checked'));   // yes it is but the graphic has not toggled. Top left of toggle.png is has word "YES"

スタイルが変更されていない場合、何が欠けているのか疑問に思っています。手がかりを歓迎し、事前に感謝します。ケビン

4

1 に答える 1

0

チェックボックス要素で「checked」クラスを切り替えますが、動的に作成された a-tag 用に変更したいとします。だから変えてみて

$("#uitem_autorenew").toggleClass("checked");

$(".toggle").toggleClass("checked");
于 2013-08-18T21:31:57.320 に答える