$.confirm还是jQuery中的confirm()?

$.confirm还是jQuery中的confirm()?,jquery,Jquery,在插件中调用$.confirm和confirm()有什么区别 var jconfirm, Jconfirm; (function ($) { "use strict"; $.fn.confirm = function (options) { if(typeof options === 'undefined') options = {}; /* * Alias of jconfirm to emulate native confi

在插件中调用$.confirm和confirm()有什么区别

var jconfirm, Jconfirm;
(function ($) {
    "use strict";
    $.fn.confirm = function (options) {
        if(typeof options === 'undefined') options = {};
        /*
         *  Alias of jconfirm to emulate native confirm
         */
        var $this = $(this);
        $this.on('click', function (e) {
            e.preventDefault();
            if ($this.attr('href'))
                options['confirm'] = function () {
                    location.href = $this.attr('href');
                };
            $.confirm(options);
        });
        return $this;
    };
    $.confirm = function (options) { <-- HERE
        /*
         *  Alias of jconfirm
         */
        return jconfirm(options);
    };
var jconfirm,jconfirm;
(函数($){
“严格使用”;
$.fn.confirm=功能(选项){
if(typeof options=='undefined')options={};
/*
*用于模拟本机确认的jconfirm别名
*/
var$this=$(this);
$this.on('click',函数(e){
e、 预防默认值();
如果($this.attr('href'))
选项['confirm']=函数(){
location.href=$this.attr('href');
};
美元。确认(选项);
});
退还$this;
};
$.confirm=函数(选项){First
$.confirm()
≠ <代码>确认()

confirm()
是一个内置JavaScript函数,它返回一个布尔值:

$.confirm
由用户/插件使用以下方式定义:

$.confirm = function () {
  // stuff
}

// or using $.fn.extend.
$.fn.extend({
    confirm: function(options) {
        var defaults = {
        };
        options = $.extend(defaults, options);
        return this;
    }
});
解决方案

对于jConfirm,它使用回调函数。因此,无论您做什么,都需要使用回调函数:

jConfirm('Some Title', 'Are you sure you want to delete your profile photo?', function(r) {
  // here `r` will be `true` or `false`.
  alert(r);
});
首先
$.confirm()
≠ <代码>确认()

confirm()
是一个内置JavaScript函数,它返回一个布尔值:

$.confirm
由用户/插件使用以下方式定义:

$.confirm = function () {
  // stuff
}

// or using $.fn.extend.
$.fn.extend({
    confirm: function(options) {
        var defaults = {
        };
        options = $.extend(defaults, options);
        return this;
    }
});
解决方案

对于jConfirm,它使用回调函数。因此,无论您做什么,都需要使用回调函数:

jConfirm('Some Title', 'Are you sure you want to delete your profile photo?', function(r) {
  // here `r` will be `true` or `false`.
  alert(r);
});

谢谢,$.myFunction和myFunction之间有什么区别?为什么我应该使用
$.
而不是函数的名称?@Paul
$。
在任何函数前面,它是对象
$
的成员函数。在这里,
$
是jQuery对象,
确认
$
的对象。明白了吗?我会接受的,别担心,我不完全确定你的意思:我使用
$而不是仅仅调用函数名,会有什么变化呢?我知道
这个
在插件中,或者只是调用函数,但我不确定
$到底做了什么。伙计,
$。有些东西属于
$
对象。
$
是jQuery对象或类似于
var Paul={};
的对象。好吧,这对插件(getter/setter)中的代码是有意义的,但它们都使用这两种方式,所以我想两者之间一定有区别。谢谢,那么$.myFunction和myFunction之间的区别是什么?为什么我应该使用
$。
而不是函数的名称?@Paul
$。
在任何函数之前,它是对象
$
的成员函数。这里,
$
是jQuery对象,并且
confirm
$
的对象。明白了吗?我会接受,别担心,我不完全确定你的意思:我使用
$会有什么变化。
而不仅仅是调用函数的名称?我知道
这个
在插件中,或者只是调用函数,但我不确定是什么de>$。
确实如此。伙计,
$。有些东西属于
$
对象。
$
是jQuery对象或类似
var Paul={};
的对象。好吧,这对插件(getter/setter)中的代码是有意义的,但它们都是使用这两种方式的,所以我想这两者之间一定有区别。