2014-06-13 15 views
0

我试图居中jquery对话框的问题。运行这段代码时,对话框出现在浏览器窗口的左上角。我也尝试使用onclick javascript事件执行代码,所以没有“加载”问题。我看了一些关于同一个问题的“计算器”的问题,但他们都没有为我工作。jquery对话框不居中

出了什么问题?一定是一件简单的事情。

谢谢

<!DOCTYPE HTML> 
<html> 
<head> 
<!--My jQuery library code location --> 
<script src="/jQuery/jquery-1.7.2.js"></script> 
<script src="/jQuery/js/jquery.ui.widget.js"></script> 
<script src="/jQuery/js/jquery.ui.dialog.js"></script> 
<script src="/jQuery/js/jquery.ui.core.js"></script> 
<script src="/jQuery/js/jquery.ui.mouse.js"></script> 
<script src="/jQuery/js/jquery.ui.draggable.js"></script> 
<script src="/jQuery/js/jquery.ui.resizable.js"></script> 
<link rel="stylesheet" href="/jQuery/css/base/jquery.ui.all.css"> 

<script type="text/javascript" > 
$(document).ready(function(){ 
    $("#span-msg").empty().append("Message"); 
    $("#div-err-msg").dialog({ 
    modal: true, 
    title: "Testing", 
    position: "centre" 
    }); 
}); 
</script> 
<body> 

<div id="div-err-msg" style="display:none;"> 
<span id="span-msg"></span> 
</div> 

</body> 
</head> 
</html> 

你应该能够复制并粘贴上面的代码复制,只是点了jQuery SRC在您的环境中正确的位置

+1

仅供参考,您的交易''标签是放错了地方。它应该在'' – asprin

回答

0

我认为你有一个错字那里,应该是:position: "center"

0

更换

position: "centre" 

position: "center" 

这应该肯定有效。

0

首先您关闭HEAD标签的地方不正确。

而在您的代码中存在拼写错误:"centre"应该是"center"

试试这个:

$("#div-err-msg").dialog({ 
    modal: true, 
    title: "Testing", 
    position: "center" 
    }); 

默认情况下,它总是窗口的中心,你没有必要给UI的对话框position

Default : { my: "center", at: "center", of: window } 

Positioning of a UI-dialog

试试这个代码(不选项 - 位置):

$("#div-err-msg").dialog({ 
    modal: true, 
    title: "Testing" 
}); 

Working Fiddle

注意:尝试这些更改并让我知道它的工作与否。

+0

之前,不是*一些*,但这是javascript代码中唯一的错误 – asprin

+0

感谢@asprin:纠正我。 :) –

0

您的头标签需要在博德标签之前关闭。

然后从代码中删除所有不需要的js参考文件。添加以下代码。

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script> 

JQuery的:

$("#LinkId").click(function() { 
     $("#div-err-msg").dialog({ 
      title: "Dialog box", 
      height: 300, 
      modal: true 
     }); 
    }); 

演示:

http://jsfiddle.net/8bNRp/1/