繁体   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