0

テキスト ボックスとドロップダウンがある検索フォームがあり、その一部が機能していません。オプションをクリックして非表示にすると機能します。別のオプションを選択すると、バックアップが表示されます。

ここに例があります。

特定のオプションを選択すると、別のテキスト ボックスが非表示になり、表示または非表示になります。何かを選択してからナビメニューに移動し、戻って非表示にする必要がある1つのボックスを表示すると. これが私が物事を隠すために使用しているコードです。デフォルトに戻さず、ページの読み込み時に非表示にする理由がわかりません。これはカミソリビューページにあります。

 @*hidefields - Spec Guide*@


//condition fields for the end user request form make sure you change the field ID to yours. 
$(document).ready(function () {
    //check to see if you are on the end users request page
    if (location.pathname === '/Reporting/Summary') {
        //if (document.location.href='/Tickets/New'){
        //toggle the field ,description and title invisible
        $('label for="CustomFieldValue@field.FieldID":contains(* On what page of the Spec Guide:)').toggle();
        $('input#CustomFieldValue3').parent().toggle();

        //monitor the dropdown field
        $('select#CustomFieldValue2').change(function(endUserselect) {
            //grab the value of the dropdown
            var userSelection = $('select#CustomFieldValue2 option:selected').text();

            //do the compare and toggle the field ,description and title visible 
            if (userSelection === 'Spec Guide') {
                $('label for="CustomFieldValue@field.FieldID":contains(* On what page of the Spec Guide:)').toggle();
                $('input#CustomFieldValue3').parent().toggle();
            }
            //hide them again if the user changes his mind
            else {
                $('label for="CustomFieldValue@field.FieldID":contains(* On what page of the Spec Guide:)').hide();
                $('input#CustomFieldValue3').parent().hide();
            }

        });

    }
});
@*hidefields - Spec Guide*@
4

1 に答える 1

0

これはおそらくキャッシュの問題です。

別のページに移動して [戻る] ボタンをクリックすると、JavaScript が再度実行されないことがあります。代わりに、フォームの最新バージョンが表示されます。

これに代わるもの(常に機能させたい場合)は、ページをリセットするためのアンロードイベントになると思います。

ユーザーがページから移動すると、unload イベントが window 要素に送信されます。これは、多くのことの 1 つを意味する可能性があります。ユーザーがリンクをクリックしてページを離れたか、アドレス バーに新しい URL を入力した可能性があります。進むボタンと戻るボタンがイベントをトリガーします。ブラウザ ウィンドウを閉じると、イベントがトリガーされます。ページのリロードでも、最初にアンロード イベントが作成されます。

$(window).unload(function () {
    // Here set the default options/hide/show dom elements for your form
});

試してみて、うまくいくかどうか教えてください。

于 2013-01-16T02:53:03.533 に答える