jConfirm未定义
问题描述:
我有一个简单的脚本,提示用户确认删除,然后它只是提醒他们该过程已正确完成。jConfirm未定义
我尝试使用jConfirm和JavaScript控制台吐出: “的ReferenceError:未定义jConfirm”
<!-- jConfirm -->
// the script is referenced properly
<script src="/js/jconfirm/jquery.jconfirm-1.0.min.js"></script>
<script>
function careersDelete(career_id) {
jConfirm('Are you sure you want to delete this career?', 'Delete Career', function (x) {
if (x) {
jQuery.ajax({
url: "ajax_career_delete.php",
type: "GET",
data: "career_id=" + career_id,
success: function (response) {
alert('Career deleted');
}
});
}
});
}
在应该使确认对话框中的按钮,我有:
<a href="#" onclick="careersDelete('<?php echo $career_id; ?>')">delete</a>
答
如果你退房these examples你会发现你需要单独提供jquery,并且jconfirm仅在其名称空间内定义。因此,你需要在你的代码添加了两两件事:
<script src="/js/jquery.js"></script> <!-- or wherever jquery.js's path is -->
...
$.jconfirm('Are you sure ...
// note jquery's $. namespace; and the non-capitalized "c" in jconfirm
此外,$.jconfirm
函数调用没想到字符串。它的签名是:
function(options, callback)
而且callback
不与任何参数(因此你x
会undefined
)执行。它看起来像你想要的东西沿线︰
function careersDelete(career_id) {
jQuery.jconfirm({
message: 'Are you sure you want to delete this career?',
title: 'Delete Career'
}, function() {
jQuery.ajax({
url: "ajax_career_delete.php",
type: "GET",
data: "career_id=" + career_id,
success: function (response) {
alert('Career deleted');
}
})
});
}
是'jQuery'和'jConfirm'库正确包括? – pes502
是的,他们都正确加载... – Hugo