在我的Web應用程序中,我爲文本框定義了一個更改事件,該事件正在調用ajax方法並將文本框值存儲到會話中。我有一個名爲「test」的按鈕,它將檢查文本框中輸入文本的驗證,它將從會話中獲取字符串並進行驗證。javascripts中的競態條件
<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
$("input", form).change(function() {
//using ajax to store the text value to session
});
$("#validateAmt").click(function() {
//using another ajax to check the value stored in session
});
});
</script>
</head>
<body>
<input type="text" id="amount">
<input type="button" id="validateAmt" value="validate"/>
</body>
</html>
但有時會發生什麼情況是,當我在文本框,無需點擊以外的任何地方進入的東西,如果我在「測試」按鈕,直接點擊,其中按鈕事件首先觸發(這與會話舊值驗證)和文本框更改事件觸發器。所以目前我想在JavaScript中使用布爾標誌並調用第一個文本框更改事件。對於這種情況有沒有任何有效的解決方案?而且這些方法將如何執行?它會一個接一個地並行發生還是繼發發生?
什麼是這一切的地步,只是驗證時被提交 – Esailija 2012-08-07 18:04:18
形式禁用按鈕,直到文本框調用返回。 – asawyer 2012-08-07 18:09:15
JavaScript沒有線程,所以它會按順序運行。 – 2012-08-07 18:13:12