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> 
+0

是'jQuery'和'jConfirm'库正确包括? – pes502

+0

是的,他们都正确加载... – Hugo

如果你退房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不与任何参数(因此你xundefined)执行。它看起来像你想要的东西沿线︰

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'); 
      } 
     }) 
    }); 
} 
+0

嗨blgt谢谢你帮助它说TypeError:$ .jconfirm不是一个函数。 – Hugo

+0

+1 :)很好回答 – pes502

+0

真是太棒了!非常感谢并解释它,而不仅仅是给出答案。我必须回到带有JS的绘图板上,因为有些概念我不认为我完全理解。再次感谢。 – Hugo