我的按钮使用 AJAX 向数据库添加信息并更改按钮文本。但是,我希望单击一次后禁用该按钮(否则该人可以向数据库中的信息发送垃圾邮件)。我该怎么做?
HTML
<button class="btn btn-lg btn-primary" id='roommate_but' onclick='load(<?php echo $user_id;?>)'><span class="glyphicon glyphicon-plus"></span> Add Person</button>
Javascript/AJAX/JQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
function load(recieving_id){
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("roommate_but").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','include.inc.php?i=' + recieving_id, true);
xmlhttp.send();
}
最佳答案
*已更新
jQuery
版本如下所示:
function load(recieving_id){
$('#roommate_but').prop('disabled', true);
$.get('include.inc.php?i=' + recieving_id, function(data) {
$("#roommate_but").html(data);
});
}
关于javascript - 在 JQuery 中单击后禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23597913/