2015-01-20 66 views
0

我有一個非常奇怪的問題與twitter引導警報框。下面是示例我試圖執行BootStrap警報行爲奇怪

<script src="js/jquery.js"></script> 
<script src="js/jquery.min.js"></script> 
<script src="js/bootstrap.min.js"></script> 
<script type="text/javascript" src="js/bootstrap-dialog.js"></script> 
<link rel="stylesheet" href="css/bootstrap.min.css"> 
<link rel="stylesheet" href="css/bootstrap-theme.min.css"> 
<link rel="stylesheet" href="css/bootstrap-dialog.css"> 
<title>Insert title here</title> 
<script> 
function callMe(){ 
    test(); 
    BootstrapDialog.alert('Bye'); 
} 
    function test(){ 
      BootstrapDialog.alert('hello'); 
    } 
</script> 
</head> 
<body> 
<input type="button" name="button" value="button" onclick="callMe()"/> 
</body> 
</html> 

的結果應該是:你好---->再見

結果如來:再見---->你好

如果我評論一個Bootstrap警報框然後也是相同的結果(沒有重疊的點框)。

function callMe(){ 
    test(); 
} 
    function test(){ 
    alert('inside test'); 
      BootstrapDialog.alert('hello'); 
      alert('outside test'); 
    } 
</script> 

結果來爲:內部測試--->外測試--->你好 結果應該是:內部測試--->你好--->外測試

回答

0

這是因爲hello對話框在另一個之後。
您首先撥打電話創建hello對話框,並在第一個對話框的頂部創建對話框bye,即第二個對話框覆蓋第一個對話框。

+0

其不正確,如果我執行如下函數callMe(){test;}; //BootstrapDialog.alert('VBye'); } \t function test(){ \t alert('inside test'); BootstrapDialog.alert('hello'); alert('outside test'); } ...結果是 - >內部測試---外部測試--->你好 – harpal18 2015-01-21 03:30:34

1

我認爲這是因爲調用是異步的。控制從test()返回所花費的時間超過BootstrapDialog.alert('Bye');

如果您將時間間隔設爲1秒。如: setInterval(BootstrapDialog.alert('Bye'), 1000);或使用回調方法 jQuery回調函數

這是一個很好的機會開始使用「jQuery Deferred」

此計算器鏈接sequencing function calls in javascript - are callbacks the only way? 可能會有所幫助。

+0

謝謝@rpandey :) – harpal18 2015-01-21 10:52:43

+0

:) @ hppy18 ....... – rpandey 2015-01-21 11:47:43

+0

@ketan感謝格式化: ) – rpandey 2015-03-04 21:49:31