0
任何人都可以告訴我如何我可以隱藏/刪除加載按鈕,當我收到來自ajax調用(例如我有未定義或空值)的某些響應?我嘗試使用$('#mango')。hide();但它並沒有爲我刪除按鈕!但是我收到了警報,確認我從api獲得了null或undefined值。希望有人能幫我解決這個.Thanks如何隱藏ajax響應中的onclick按鈕?
代碼:
<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>
什麼是'maxnumId'值?它是否在控制檯中表示「undefined」或「null」? –
.hide()隱藏元素。 .remove()將其從DOM中刪除。 –
你試過刪除?你能寫你的html代碼嗎? – nole