dongmu6225 2016-02-23 01:08
浏览 328
已采纳

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>
";
  • 写回答

1条回答 默认 最新

  • dsf55s1233 2016-02-23 01:21
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失