Ajax按钮启用/禁用

问题描述:

How do I enable and Disable the button with AJAX get error admin.php:15 Uncaught ReferenceError: $ is not defined

function validate() {
    // Find the validation image div
    var validationElement = document.getElementById('nameValidation');
    // Get the form values
    var password1 = document.forms["Admin"]["password1"].value;
    var password2 = document.forms["Admin"]["password2"].value;
    // Reset the validation element styles

    validationElement.style.display = 'none';
    validationElement.className = 'validation-image';
    // Check if password2 isn't null or undefined or empty
    $('#savepasswd').prop('disabled', true);
    if (password2) {
        // Show the validation element
        validationElement.style.display = 'inline-block';
        // Choose which class to add to the element
        $('#savepasswd').removeAttr('disabled');
        validationElement.className += 
            (password1 == password2 ? ' validation-success' : ' validation-error');
    }
}

PHP code.

$msg .= "  <td><input type=\"submit\" name=\"savepasswd\"  id=\"savepasswd\" value=\"Save Access\" class=\"inputadmin\"></td>
";

如何使用AJAX启用和禁用按钮get error admin.php:15未捕获的ReferenceError:$未定义 p>

  function validate(){
 //找到验证图像div 
 var validationElement = document.getElementById('nameValidation'); 
 //获取表单值 
 var password1 = document.forms [“Admin”] [“password1”]。value; 
 var password2 = document.forms [“Admin”] [“password2”]。value; 
 //重置验证元素 styles 
 
 validationElement.style.display ='none'; 
 validationclement.className ='validation-image'; 
 //检查password2是否为null或未定义或为空
 $('#savepasswd'  ).prop('disabled',true); 
 if(password2){
 //显示验证元素
 validationElement.style.display ='inline-block'; 
 //选择要添加到的类 元素
 $('#savepasswd')。removeAttr('disabled'); 
 validationElement.className + = 
  (password1 == password2?  'validation-success':'validation-error'); 
} 
} 
  code>  pre> 
 
 

PHP代码。 p>

  $ msg。=“&lt; td&gt;&lt; input type = \”submit \“name = \”savepasswd \“id = \”savepasswd \“value = \  “保存访问权限”class = \“inputadmin \”&gt;&lt; / td&gt; 
“; 
  code>  pre> 
  div>

You apparently don't have jQuery loaded. You don't need it just for this, you can use plain Javascript.

To disable the button:

document.getElementById('savepasswd').disabled = true;

To enable the button:

document.getElementById('savepasswd').disabled = false;