javascript - django 管理列表自定义按钮的点击事件
问题描述
- 管理员.py
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)
- js/common.js
(function($) {
$(".call_alert").on("click", function() {
alert($(this).data("msg")); // ★★★ Dose not!!! ★★★
});
})($);
错误信息 :
Uncaught TypeError: $ is not a function at common.js:2 at common.js:5
我怎样才能收到警报消息?
这是不可能的吗?
请帮忙..
解决方案
最后,我明白了。:)
脚本更改如下。
if(!$) $ = django.jQuery;
$(function(){
$(".call_alert").on("click", function() {
alert($(this).data("msg"));
});
});
感谢你所做的一切。:D
推荐阅读
- jestjs - 期望数组参数具有设置长度
- html - Textarea占位符奇怪的差距(reactjs)
- jquery - 使用 Dropdownlist Visual Basic 调用 MVC actionResult
- c++ - 设置数组元素时的奇怪结果(C++/pybind11)
- r - 如何用 R 语言在 LaTeX 中的“正常”句子中格式化 R 代码?
- python - 我的 while 循环中的变量没有被更新
- java - 在代码下找不到任何消息...对于语言环境 en_US
- salesforce - VSCode 没有推送代码,也没有抛出任何错误
- python - 使用python从API下载
- android - 如何在 Android 中的其他布局上显示半透明图像?