【问题标题】:Disable selection box without removing value from post禁用选择框而不从帖子中删除值
【发布时间】:2009-05-26 12:41:26
【问题描述】:

在我当前的 asp.net-mvc 项目中,我的一个页面允许用户在发出更新多个值的发布请求后在下拉框中选择一个值。 为了确保回发的延迟不会让用户混淆选择另一个值(从而创建另一个帖子、创建另一个延迟等),我将选择的禁用属性设置为 true。
但是,禁用的输入不会提交给 post call。

我怎样才能让用户在视觉上清楚地知道工作正在进行中,并且在不从帖子中删除输入的情况下无法选择新值?

【问题讨论】:

    标签: c# .net html asp.net-mvc postback


    【解决方案1】:

    是的,这也让我很烦。

    基本上,您需要做的是隐藏旧按钮并将其替换为禁用的按钮,以便用户看起来相同。这样它仍然提交,但不能重复提交。

    实际上,我在Problem with disabling submit buttons on form submit 找到了似乎与此相同的内容。

    【讨论】:

      【解决方案2】:

      根据您的回答,我猜您已经在使用 jQuery。在那种情况下,你为什么不获取选择框的值,禁用它,然后自己发布值?

      奖励:BlockUI 是一个不错的 jQuery 插件,可以很好地阻止 UI。

      【讨论】:

        【解决方案3】:

        我在 Cletus 的帖子中找到的答案都不是我想要的。
        这是我想出的。它不是 100% 可重复使用的,但它可以满足我的需要并且可以随时改进/编辑。

        $('#productMixSelectorForm').change(function() { $(this).ChangeSelection() });
        
        jQuery.fn.ChangeSelection = function() {
            var html = $('<div class="hidden">');
            $(this).find('select, input').each(function() {
                if ($(this).hasClass('hidden') == false) {
                    //Clone the original one into the hidden div
                    html.append($(this).clone());
                    //Disable the original (visible) one and make it's name unique again
                    $(this).attr("disabled", true);
                    var name = $(this).attr("name");
                    $(this).attr("name", name + "disabledDummy");
                }
            });    
            //Add the collection of clones to the form so they get submitted
            $(this).append(html);
            $(this).submit();
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-09-27
          • 1970-01-01
          • 2019-01-10
          • 2015-05-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多