【发布时间】:2017-06-25 05:22:51
【问题描述】:
我坚持让超时工作。我已经有一个工作代码,但在我看来这是错误的方法。
工作代码,但可能不是最好的:
/* Autosave */
// On load we hide all autosave messages.
$('.jform_params_autosave-cg').hide();
// Below is the function that handles the autosave.
$.fn.autoSave = function(){
// We remove the autosave message from it's place defined by the xml and add it to the system message container.
var autosavemessage = $('.jform_params_autosave-cg');
autosavemessage.detach();
autosavemessage.appendTo('#system-message-container');
// Now we show the message.
$('.jform_params_autosave-cg').show();
// Here we save the extension.
Joomla.submitbutton('module.apply');
}
// On change of the below elements we run the autosave.
//------------------------------------------//
// DUPLICATE AUTOSAVE FUNCTION BELOW
//------------------------------------------//
// Autosave: Theme Selection
$("#jform_params_theme_selection").change(function() {
$.fn.autoSave();
});
// Autosave: Add Content
$("a.group-add.btn.btn-mini.button.btn-success").click(function() {
setTimeout(
function()
{
$.fn.autoSave();
}, 5000);
});
功能:
$.fn.autoSave = function(){
// We remove the autosave message from it's place defined by the xml and add it to the system message container.
var autosavemessage = $('.jform_params_autosave-cg');
autosavemessage.detach();
autosavemessage.appendTo('#system-message-container');
// Now we show the message.
$('.jform_params_autosave-cg').show();
// Here we save the extension.
Joomla.submitbutton('module.apply');
}
函数调用
$("#jform_params_theme_selection").change(function() {
$.fn.autoSave();
});
有超时的函数调用
$("a.group-add.btn.btn-mini.button.btn-success").click(function() {
setTimeout(
function()
{
$.fn.autoSave();
}, 5000);
});
我想达到什么目的
- 在函数内部设置超时。
- 定义调用函数时的超时时间。
定义我的意思是称它为$.fn.autoSave(5000);或$.fn.autoSave().timeout(500);之类的东西
我一直在尝试获得有效的代码,但到目前为止还没有成功。每当我获得更多成功或添加细节时,都会不断更新这篇文章。
感谢大家的帮助。
任何指向现有 SO 问题的链接也将不胜感激,因为我可能会在谷歌上搜索错误的关键词。
【问题讨论】:
-
您正在寻找“创建插件”检查这里learn.jquery.com/plugins/basic-plugin-creation
-
@TolgahanAlbayrak 谢谢你的链接。确实,这就是我正在寻找的。不幸的是,在我接管页面的快速浏览中,没有超时的示例。打算从头到尾阅读它,但不要认为它在页面上。
标签: javascript jquery function joomla timeout