2013-05-15 48 views
0

正如標題所述,我在javascript中遇到了一個奇怪的錯誤。 在我的PHP我呼應了JavaScript呈現jquery彈出警告框到屏幕。自定義警報在JQuery UI中不起作用

echo '<link rel="stylesheet" 
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/> 
       <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
       <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
       <link rel="stylesheet" href="/resources/demos/style.css" /> 
       <script src="../functions.js"></script> 
       <script type="text/javascript"> JQueryAlert("HELLO!", 120);</script>'; 

functions.js

 function JQueryAlert(message,windowHeight){ 
    if (!windowHeight) var windowHeight = 470; 

    $("#msgdialog").remove(); 

    $("body").append("<div id=\'msgdialog\'></div>"); 

    thatmsg = $("#msgdialog"); 

    $("#msgdialog").dialog({ 
     resizable: false, 
     draggable: false, 
     width: 770, 
     height: windowHeight, 
     context: thatmsg, 
     modal: true, 
     autoOpen: false, 
     buttons: { 
      "Cancel" : function(){ 
       thatmsg.dialog("close"); 
      }, 
      "OK" : function(){ 
       loadPage("combat.php"); 
      } 
     } 
    });  

    $("#msgdialog").html(message); 
    $("#msgdialog").dialog(\'open\'); 
} 

然而,只顯示彈出警告框有時。剩下的時間屏幕閃爍並且不顯示彈出框。任何想法,爲什麼這樣表現?謝謝你的時間。

+0

http://phpfiddle.org/ - 一個活生生的例子會更容易identift問題 – Ryan

+2

控制檯應該告訴你的故事.. F12 now .. – techfoobar

+0

任何相關的控制檯輸出? – Sirko

回答

0

你可以試着把你的函數調用放在文檔準備好的eventhandler中嗎?

事情是這樣的:

<script> 
    $(function() { 
    JQueryAlert("HELLO!", 120); 
    }); 
</script> 

我的猜測是因爲你在訪問你的函數的DOM,有時DOM沒有完全你的代碼執行前加載中...

0

它是不是一個錯誤...
你不能操縱頁面元素之前,他們實際呈現的地方。
而不是JQueryAlert(「HELLO!」,120);

使用

$(document).ready(function() { 
    JQueryAlert("HELLO!", 120); 
} 

這將顯示您的警報時,文檔準備好

+0

是的,我試過了。它仍然沒有加載。 – user2361103