我有一个简单的脚本提示用户确认删除,然后它只是提醒他们该过程已正确完成。
我尝试使用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>
答案 0 :(得分:2)
如果您签出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');
}
})
});
}