javascript - 如何在ajax响应中隐藏onclick按钮?

标签 javascript html ajax

有人能告诉我当我收到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/

相关文章:

javascript - rails 中的 rjs 类型错误?

ajax - 相当于 XHR 或 Ajax 库中的 Fetch 'no-cors' 模式?

javascript - 更改路径时 react 路由器不工作

javascript - 将 $timeout 与 Jasmine 的模拟时钟一起使用的单元测试 Angular 服务

javascript - Array() 中的 getElementById() 会覆盖数组中的其他元素

javascript - 如果盒子是特定颜色,我该如何更改它的颜色?

javascript - 如何在 jQuery 中设置下拉列表的 SELECTED 属性?

javascript - PHP : Preventing multiple javascript inclusions

jquery - jQuery keydown和mouseDown函数?

jquery - 使用 this.securejson = true;