我有一个简单的脚本,提示用户确认删除,然后只是警告他们该过程已正确完成。
我尝试使用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');
}
})
});
}