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 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员