2015-01-20 65 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