gpt4 book ai didi

jquery 确认插件在与 jquery 合并/压缩时不起作用

转载 作者:行者123 更新时间:2023-12-01 06:02:20 32 4
gpt4 key购买 nike

我发现this jquery plugin用于内联确认。我将所有 js 文件压缩/合并为一个以优化 http 请求(这是手动的)。现在这个文件的顶部是 jquery Library 1.7.1,然后我放入内联确认插件。所以这个插件在位于带有 jquery 库的文件中时不起作用。我有什么问题吗?

e.x:正常:分开(此有效)

<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/inline-confirmation.js"></script>

e.x:压缩到一个文件(jquery + inline-confirmation)不起作用

<script type="text/javascript" language="javascript" src="./js/main.js"></script>

内联确认插件:

jQuery.fn.confirm = function(options) {
options = jQuery.extend({
msg: 'Are you sure?',
stopAfter: 'never',
wrapper: '<span></span>',
eventType: 'click',
dialogShow: 'show',
dialogSpeed: '',
timeout: 0
}, options);
options.stopAfter = options.stopAfter.toLowerCase();
if (!options.stopAfter in ['never', 'once', 'ok', 'cancel']) {
options.stopAfter = 'never';
}
options.buttons = jQuery.extend({
ok: 'Yes',
cancel: 'No',
wrapper:'<a href="#"></a>',
separator: '/'
}, options.buttons);

// Shortcut to eventType.
var type = options.eventType;

return this.each(function() {
var target = this;
var $target = jQuery(target);
var timer;
var saveHandlers = function() {
var events = jQuery.data(target, 'events');
if (!events && target.href) {
// No handlers but we have href
$target.bind('click', function() {document.location = target.href});
events = jQuery.data(target, 'events');
} else if (!events) {
// There are no handlers to save.
return;
}
target._handlers = new Array();
for (var i in events[type]) {
target._handlers.push(events[type][i]);
}
}

// Create ok button, and bind in to a click handler.
var $ok = jQuery(options.buttons.wrapper)
.append(options.buttons.ok)
.click(function() {
// Check if timeout is set.
if (options.timeout != 0) {
clearTimeout(timer);
}
$target.unbind(type, handler);
$target.show();
$dialog.hide();
// Rebind the saved handlers.
if (target._handlers != undefined) {
jQuery.each(target._handlers, function() {
$target.click(this.handler);
});
}
// Trigger click event.
$target.click();
if (options.stopAfter != 'ok' && options.stopAfter != 'once') {
$target.unbind(type);
// Rebind the confirmation handler.
$target.one(type, handler);
}
return false;
})

var $cancel = jQuery(options.buttons.wrapper).append(options.buttons.cancel).click(function() {
// Check if timeout is set.
if (options.timeout != 0) {
clearTimeout(timer);
}
if (options.stopAfter != 'cancel' && options.stopAfter != 'once') {
$target.one(type, handler);
}
$target.show();
$dialog.hide();
return false;
});

if (options.buttons.cls) {
$ok.addClass(options.buttons.cls);
$cancel.addClass(options.buttons.cls);
}

var $dialog = jQuery(options.wrapper)
.append(options.msg)
.append($ok)
.append(options.buttons.separator)
.append($cancel);

var handler = function() {
jQuery(this).hide();

// Do this check because of a jQuery bug
if (options.dialogShow != 'show') {
$dialog.hide();
}

$dialog.insertBefore(this);
// Display the dialog.
$dialog[options.dialogShow](options.dialogSpeed);
if (options.timeout != 0) {
// Set timeout
clearTimeout(timer);
timer = setTimeout(function() {$cancel.click(); $target.one(type, handler);}, options.timeout);
}
return false;
};

saveHandlers();
$target.unbind(type);
target._confirm = handler
target._confirmEvent = type;
$target.one(type, handler);
});
}

谢谢

最佳答案

我同意 rgin 的观点,我们可能需要查看整个文件(并且您应该将其分开),但我认为可能只是文件被缓存了。按 ctrl-F5 或手动清除缓存。

关于jquery 确认插件在与 jquery 合并/压缩时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10034041/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com