jQuery:运行“成功:"后重新启用禁用的输入按钮 [英] jQuery: Re-enabling disabled input buttons after 'success:' is run

查看:86
本文介绍了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);

这篇关于jQuery:运行“成功:"后重新启用禁用的输入按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆