有人能告诉我当我收到ajax调用的某些响应时如何隐藏/删除loadmore按钮(例如我得到未定义或空值)吗?我尝试使用$('#mango').hide();但它并没有为我删除按钮!但我收到了警报,确认我从 api 获得了 null 或未定义的值。希望有人帮我解决这个问题。谢谢
代码:
<script>
var maxnumId = null;
function callApi() {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "https://api.somesite.com/......"),
success: function(data) {
maxnumId = data.pagination.next_num_id;
if (maxnumId === undefined || maxnumId === null) {
alert('End!');
//remove the loadmore button here
$('#mango').hide();
}
}
});
}
</script>
<body>
<br>
<center>
<button id="mango" onclick="callApi()">Load More</button>
</html>
最佳答案
假设满足 if 条件(maxnumId === undefined || maxnumId === null
),你可以尝试用普通的 js 来实现:
document.getElementById('mango').style.visibility = 'hidden';
document.getElementById('mango').style.display = 'none';
关于javascript - 如何在ajax响应中隐藏onclick按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30240008/