2012-04-16 60 views
3

試圖學習jquery,我正處於放棄的邊緣!花了2天試圖讓對話框顯示!Jquery對話框窗口示例不能正常工作

任何人都可以幫助爲什麼此代碼不起作用?我只是在頁面頂部打招呼!

的jQuery:

<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script> 
<script src="js/jquery.ui.core.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    var $dialog = $('#dialog') 
    //.html('This dialog will show every time!') 
    .dialog({ 
     autoOpen: false, 
     title: 'Basic Dialog' 
    }); 
    $('#opener').click(function() { 
     $dialog.dialog('open'); 
     // prevent the default action, e.g., following a link 
     return false; 
    }); 
}); 
</script> 

HTML

<div id="dialog">hello</div> 
<button id="opener" style="margin-left:66px;margin-top:3px;font-size:11px;width:60px">Click</button> 
+0

這是一個樣式表的問題。他的代碼很好。 – 2012-04-16 16:04:37

+0

確保您使用對話框小部件下載了jQuery UI包。看你的例子,你可能只抓住了核心。 – j08691 2012-04-16 16:09:35

+0

真的有什麼機會說出我需要添加什麼以及在哪裏? – JC75 2012-04-16 16:50:49

回答

2

確保您的jQuery UI Core文件包含Widget工廠。請看:

http://jqueryui.com/download

即使你沒有包含在jQuery UI的CSS文件,它應該仍然工作:

See jsFiddle demo


Try this exact code that I have out at jsBin:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset=utf-8 /> 
    <title>jQuery Dialog Demo</title> 
    <link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/cupertino/jquery-ui.css" /> 
</head> 
<body> 
    <div id="dialog" style="display: none;">hello</div> 
    <button id="opener">Open Dialog</button> 
    <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.2.min.js"></script> 
    <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.min.js"></script> 
    <script type="text/javascript"> 
    var $dialog = $("#dialog").dialog({ autoOpen: false, title: "Basic Dialog" }); 
    $("#opener").click(function() { $dialog.dialog("open"); }); 
    </script> 
</body> 
</html> 
+0

雖然他的代碼工作正常,但它不是呈現。它很可能是一個被遺忘的CSS文件,或者沒有正確鏈接。 – 2012-04-16 16:05:56

+0

如果沒有包含小部件文件,我不會看到它是如何工作的。 – 2012-04-16 16:06:52

+0

Widget是核心的一部分......不是嗎? – 2012-04-16 16:07:46

0

聽起來像是你沒有加載你的CSS樣式表。

+0

我需要什麼CSS樣式表? – JC75 2012-04-16 16:43:06

+0

我已經添加了jquery.ui.dialog.css,但仍然不能正常工作 – JC75 2012-04-16 16:49:54

+0

實際上有什麼機會說出我需要添加什麼以及在哪裏? – JC75 2012-04-16 16:51:28