簡體   English   中英

單擊提交按鈕后關於.submit 和重新加載表單值的問題

[英]Question on .submit and reloading form values AFTER the submit button is clicked

我正在使用 jQuery 1.4.3 並且有一個新手問題。

In the following.submit function, I grab the value of the selected option in the facilityCodes dropdown list after I click the submit button and then during the submit function, select the facilityCode again in the dropdown list and then disable the list so that the user不能改變它。 但是,情況是當我在單擊提交按鈕后重新加載頁面時,下拉菜單默認為第一個選項並且列表已啟用。 我顯然不了解.submit 的工作原理,因此我選擇了我在代碼中定義的選項,然后在頁面重新加載后禁用列表。 我的問題是我做錯了什么? 我使用了錯誤的事件嗎?

任何幫助/方向將不勝感激。 謝謝你。

這是我的代碼:

    $(function() {
        $("#ARTransferForm").submit(function() {
            var msgsCount = 0;

            var facilityCodeValue = $("#ARTransferForm\\:facilityCodes option:selected").val();
alert("facilityCodeValue = " + facilityCodeValue);
            if (facilityCodeValue == 0) {
                alert("To Facility Code must be selected");
                msgsCount++;
            } else {
                $('select[id$=facilityCodes]').val(facilityCodeValue);
                $("#ARTransferForm\\:facilityCodes").attr("disabled", "disabled");
            }
                });
}); 

刷新頁面將刪除您在頁面刷新之前使用 JavaScript 所做的一切。 如果您希望通過頁面重新加載來保留狀態,則需要使用服務器端代碼或設置 cookie。

當表單即將發布時,在當前頁面上調用提交事件。 您需要傳遞一個在表單加載時檢查的值(隱藏字段),您可以檢查該值以確定是否應禁用列表。

更新:

在頁面加載時,您需要檢查這是否是在發布期間設置了隱藏字段 id="disable_select" 的轉發。 如果是這樣,那么您將禁用該表單。

$(function(){
    if ($('#disable_select').val() == '1') {
        $("#ARTransferForm\\:facilityCodes").attr("disabled", "disabled");
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM