本文介绍了jConfirm没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提示用户确认删除一个简单的脚本,那么它只是提醒他们,这个过程完全正确。

我试着用jConfirm和JavaScript控制台吐出来:的ReferenceError:jConfirm没有定义

 <! -  jConfirm  - >
//脚本中引用正确
<脚本的src =/ JS / jconfirm / jquery.jconfirm-1.0.min.js>< / SCRIPT>


<脚本>
功能careersDelete(career_id){
  jConfirm('您确定要删除这个职业?,删除职业',函数(X){
    如果(x)的{
        jQuery.ajax({
            网址:ajax_career_delete.php
            键入:GET,
            数据:career_id =+ career_id,
            成功:函数(响应){
                警报('事业'中删除);
            }
        });
    }
});
 

}    

在该按钮应使确认对话框,我有:

 < A HREF =#的onclick =careersDelete('<?PHP的echo $ career_id;?>')>删除< / A>
 

解决方案

如果你看看这些例子你会看到,你需要单独源的jquery,那jconfirm只是它的命名空间中定义的。因此,你需要添加两件事情在你的code:

 <脚本的src =/ JS /的jquery.js>< / SCRIPT> <! - 或是其他地方的jquery.js的路径是 - >
...
  $ .jconfirm('你确定?
  //注意jQuery的$。命名空间;在jconfirm和非大写的C
 


此外, $。jconfirm 函数调用没想到字符串。它的签名是:

 功能(选项,回调)
 

回调不与任何参数(因此你的执行X 未定义)。它看起来像你想要的是什么线沿线的地方:

 函数careersDelete(career_id){
  jQuery.jconfirm({
       消息:你确定要删除这个职业?,
       标题:删除生涯
  }, 功能 () {
        jQuery.ajax({
            网址:ajax_career_delete.php
            键入:GET,
            数据:career_id =+ career_id,
            成功:函数(响应){
                警报('事业'中删除);
            }
        })
  });
}
 

I have a simple script that prompts the user to confirm delete, then it just alerts them that the process was completed properly.

I tried using jConfirm and the Javascript console spits out:"ReferenceError: jConfirm is not defined"

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

}

On the button that should enable the confirm dialog, I have:

<a href="#" onclick="careersDelete('<?php echo $career_id; ?>')">delete</a>
解决方案

If you check out these examples you'll see that you need to separately source jquery, and that jconfirm is only defined within its namespace. Thus you need to add two things in your code:

<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


Additionally, the $.jconfirm function call is not expecting strings. It signature is:

function(options, callback)

And the callback is not executed with any parameters (thus your x will be undefined). It looks like what you wanted was somewhere along the lines of:

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

这篇关于jConfirm没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:40