jQuery:运行“成功:"后重新启用禁用的输入按钮
如果满足指定条件,我有以下jQuery代码可以禁用某些表单按钮.调用PHP文件以将用户输入与数据库查找相匹配.如果输入与查找匹配,则禁用按钮,并显示一条消息(uinError).这是jQuery:
I have the following jQuery code in place to disable some form buttons if a specified condition is met. A PHP file is called to match the user's input to a database lookup. If the input matches the lookup, then the buttons are disabled and a message (uinError) is displayed. Here is the jQuery:
$(function()
{
$('input[id="empUIN"]').keyup(function(event)
{
var uin = $('#empUIN').val();
$.ajax(
{
type: 'POST',
url: 'uinlookup.php',
data:
{
term: uin
},
success: function(data)
{
$('#uinError').html(data);
$('#class1Buttons :input').attr('disabled', true);
}
}); //End ajax
event.preventDefault();
});
}); //End function
如果存在匹配项,则此方法有效,但是如果用户提供的输入不触发匹配项(即,如果他在输入中退格并键入新的数字),则需要重新启用按钮.现在,无论empUIN中的输入如何,按钮均保持禁用状态.
This works if there is a match, but I need to re-enable the buttons if the user provides input that does NOT trigger a match (i.e., if he backspaces over the input and types a new number). Right now, the buttons remain disabled no matter the input in empUIN.
您需要使用.prop()
:
$('#class1Buttons :input').prop('disabled', true); //true = disabled, false = enabled. Not sure what you want
在您的情况下,该方法应该有效:
In your case, that should work :
$('#class1Buttons :input').prop('disabled', data);