我有一个简单的脚本,提示用户确认删除,然后它只会提醒他们进程已经正确完成。
我尝试使用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>发布于 2014-07-16 12:54:06
如果您签出这些例子,您将看到您需要单独地源jquery,并且j确认只在它的命名空间中定义。因此,您需要在代码中添加两项内容:
<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');
}
})
});
}https://stackoverflow.com/questions/24768624
复制相似问题