[英]django admin list custom button's click event
class TestAdmin(admin.ModelAdmin):
class Media:
js = (
'js/common.js',
)
list_display = ['custom_actions']
def custom_actions(self, obj):
return mark_safe(
'<a class="button call_alert" href="#" data-msg="A">A</a> '
'<a class="button call_alert" href="#" data-msg="B">B</a>'
)
custom_actions.short_description = 'Custom Actions'
admin.site.register(Test, TestAdmin)
(function($) {
$(".call_alert").on("click", function() {
alert($(this).data("msg")); // ★★★ Dose not!!! ★★★
});
})($);
error message :错误信息 :
Uncaught TypeError: $ is not a function at common.js:2 at common.js:5
Uncaught TypeError: $ is not a function at common.js:2 at common.js:5
How can I get alert message?我怎样才能收到警报消息?
Is it impossible?不可能吗?
Please help..请帮忙..
Finally, I've got it.终于,我明白了。 :)
:)
The script was changed like below.脚本更改如下。
if(!$) $ = django.jQuery;
$(function(){
$(".call_alert").on("click", function() {
alert($(this).data("msg"));
});
});
Thank you for all.感谢你所做的一切。 :D
:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.