jQuery对话框无法正常工作

时间:2011-02-07 13:12:23

标签: javascript jquery

我有以下脚本:

<script type="text/javascript">
$( "#addLocation" ).dialog({
            autoOpen: false,
        modal: true,
        height: 700,
        width: 550,
        buttons: {
            "Add Location": function() {
                document.forms["mapform"].submit();
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
});
</script>

<script type="text/javascript">
function showLocationDialog() {
    $("#addLocation").dialog("open");
}
</script>

<div id="addLocation" style="display:none;">
<form action="" method="post" name="mapform">
<input type="text" name="name" />
<input type="submit" />
</form>
</div>

<button onclick="javascript:showLocationDialog();">Add an address</button>

按钮无法打开对话框,我无法理解为什么..任何人都可以提供帮助吗?

谢谢,

3 个答案:

答案 0 :(得分:3)

等待DOM准备就绪。

.dialog()代码粘贴到$(document).ready()$()

答案 1 :(得分:1)

1 - 将.dialog()初始化放入$(document).ready() { ... });

2 - 从按钮值后删除额外的逗号:

buttons: {
            "Add Location": function() {
                document.forms["mapform"].submit();
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }, <-- remove this, causes IE to spontaneously combust

答案 2 :(得分:0)

另一件事要尝试......

从addLocation div中删除display:none css ...对话框将在文档初始化后隐藏所有内容。已经