.glyphicon刷新
是一个动态刷新页面部分的按钮。刷新后,我希望它在5秒后点击刷新,但它只能工作一次。
为什么?
点击
$("#btnRefresh").on("click", ".glyphicon-refresh", function (e) {
console.log("clicked");
});
的setInterval
setInterval(function () {
$(".glyphicon-refresh").click();
console.log("ok");
if ($("#waitingOrders").length) {
console.log("there are new orders");
} else {
console.log("the page is empty");
}
}, 5000);
答案 0 :(得分:-1)
对我来说很好:
setInterval(function () {
$(".glyphicon-refresh").click();
console.log("ok");
if ($("#waitingOrders").length) {
console.log("there are new orders");
} else {
console.log("the page is empty");
}
}, 5000);
$("#btnRefresh").on("click", ".glyphicon-refresh", function (e) {
console.log("clicked");
});

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-refresh"></span> Refresh
</button>
&#13;