django管理员jQueryUI对话框 [英] django admin jQueryUI dialog

查看:69
本文介绍了django管理员jQueryUI对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个django管理站点项目,我想在我的change_form模板之一上添加一个简单对话框。

Well, I have a django admin site project and I want to add a simple dialog on one of my change_form template.

我添加以下代码:

将打开对话框的打开按钮:

Open button that will open the dialog:

<button id='open_dialog' onclick='javascript:$( "#comfirm_dialog" ).dialog("open");'>open</button>

对话框初始化代码:

<script>
(function($){
$( "#comfirm_dialog" ).dialog({
    autoOpen: false,
    height: 450,
    width: 550,
    modal: true,
    buttons: {
        "Add": function(){},
        Cancel: function() {$( this ).dialog( "close" );}
    },
    show: {
      effect: "blind",
      duration: 1000
    },
    hide: {
      effect: "explode",
      duration: 1000
    }
});
})(django.jQuery)

</script>

对话框本身:

<div id='comfirm_dialog' title='Comfirmation'>
    This is a dialog.
</div>

当我单击打开按钮时,什么也没有发生,但有一个错误:

When I click the 'Open' button, nothing happened but with one error:

"Uncaught TypeError: Object #<Object> has no method 'dialog' "

我做了一些研究,发现这可能是由于多种原因造成的。

I did some research and found out this may due to many reasons.

最常见的一种是我可能在某个地方两次包含Jquery。
但是,我认为我没有这样做。我只声明在'script'标签中使用'django.jQuery'。

One of the most common one is that I may include Jquery twice somewhere. However, I don't think I did it. I only declare that I am using 'django.jQuery' in 'script' tag.

有人知道我的原因吗?

谢谢。

编辑:要进行更新,

我尝试包含'jquery-ui',然后得到'未捕获的ReferenceError:jQuery未定义'

I try to include 'jquery-ui', then I got 'Uncaught ReferenceError: jQuery is not defined'

然后我尝试包含jquery(我认为我不应该这样)因为我已经使用过(django.jQuery),所以执行了两次。)并且我得到了相同的错误,即未捕获的TypeError:对象#没有方法'dialog'

Then I try to include jquery (which I think I should not do it twice, since I have used (django.jQuery).) And I got the same error that "Uncaught TypeError: Object # has no method 'dialog' "

推荐答案

尝试一下:

替换

<button id='open_dialog' onclick='javascript:$( "#comfirm_dialog" ).dialog("open");'>open</button>

<button id='open_dialog'>open</button>

$(function(){
    $('#open_dialog').click(function(){
        $("#comfirm_dialog").dialog('open'); 
    });
})

此外,请确保已包含<$ c $模板中的c> jquery-ui 源

这篇关于django管理员jQueryUI对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆