【问题标题】: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
【解决方案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();
}