我有一些HTML:的onclick被稱爲連續
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div onclick="postClick()" class="btn-simple" id="button">Solve</div>
<div id="message">
<p></p>
</div>
<script>
function postClick() {
answers = ["A", "B", "C"]
rand = answers[Math.floor(Math.random() * answers.length)];
document.getElementById("message").innerHTML = "<p>" + rand + "</p>";
$.ajax({
type: 'POST',
url: 'somefile.php',
dataType: 'text',
success: function(msg) {
if (msg) {
window.location = msg;
}
}
});
}
</script>
之前,我點擊按鈕的第一次,一切都很好。 但是,一旦我點擊了按鈕,顯示屏會自動循環查看答案,就好像我每半秒左右點擊一次按鈕。我想要的是每次點擊時顯示的不同答案。
我在做什麼錯?
編輯:
如果我登錄該函數的調用,通過
arguments.callee.caller.toString()
是按鈕點擊:
function onclick(event) { postClick() }
無法重現(Firefox 51)。提供[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 – Xufox
向我們展示您的成功回調中的代碼 – charlietfl
您可能已將「postClick()」包含在AJAX請求中的某處,您只需要「postClick」。 – Xufox