工作,我需要點擊按鈕後只有5秒跑完的功能。的setTimeout不是我的點擊數事件
控制檯顯示此消息:
VM9200:1 Uncaught ReferenceError: getId is not defined at :1:1
function getId() {
$.getJSON("https://maxtechglobal.com/vencimientos/perfil/perfil.php?cuit="+$("#cuit").val(), function(result){
for (var i = 0; i < result.data.length; i++) {
$.each(result.data[i].perfil, function(index, value) {
var id = result.data[i].perfil.id;
$("#idPerfil").val(id);
});
}
});
}
<button id="btnBuscar" onclick="setTimeout('getId()', 5000);" type="button" class="btn btn-primary text-center" name="button">Buscar</button>
我證明了這一點:setTimeout(getId, 5000);
這setTimeout("getId();", 5000);
這個:setTimeout('getId', 5000);
但任何工作
當您使用'on *'事件屬性時,'getId()'需要在窗口範圍內聲明。我打賭你已經把它放在一個document.ready處理程序下。另外請注意,您可以通過將函數引用傳遞給超時來改進代碼:'setTimeout(getId,50000);' –
該代碼應該工作減去沒有引用jQuery。我的猜測是,這不是你的實際代碼,你的實際代碼有一個文件準備包裝 – epascarello