jquery对话框加载问题

时间:2012-03-05 20:37:55

标签: jquery jquery-ui

我只想尝试使用Jquery对话框。我单击一个按钮,出现对话框。这段代码只是来自Jquery文档的直接副本(好吧,通过链接到博客文章)。

<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js"></script>
<script language="javascript" type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js"></script>
<script type="text/javascript">

var js = jQuery.noConflict();

js(document).ready(function() {
var $dialog = js('<div></div>')
    .html('This dialog will show every time!')
    .dialog({
        autoOpen: false,
        title: 'Basic Dialog'
    });

js('#axis-details').click(function() {
    $dialog.dialog('open');
    // prevent the default action, e.g., following a link
    return false;
});
});
</script>

简单的html按钮:

<button id="axis-details" >API Key</button>

我收到此错误:js("<div></div>").html("This dialog will show every time!").dialog is not a function

首先,我想确保这里的代码没有做错。通常这意味着它没有适当地加载jquery-ui,但我可以看到它与firebug一起加载得很好。我还确保它不与任何其他包冲突,因此noConflict()。

任何我出错的提示都会受到赞赏。

2 个答案:

答案 0 :(得分:2)

copied to JSFiddle

它工作正常。你的问题必须在这段代码之外

答案 1 :(得分:1)

@Travis J有这个权利。似乎与.noConflict()和jQuery UI存在某种冲突。多么具有讽刺意味;)

删除noConflict()可以使这个工作。