我知道我的问题需要更多澄清,所以让我解释一下:
当我访问 $.fn.extend 的 jquery api 文档时,我个人对创建如下所示的自定义 jquery 函数是多么容易感到震惊:
$('input[type="checkbox"]').check();
链接在这里:http://api.jquery.com/jquery.fn.extend/ http://api.jquery.com/jquery.fn.extend/
但是,如果您想向这样的函数添加功能(双关语):
check({ timer: 1000, redo: 4000, displayAt: 'someID' });
// filler parameters
确切地说,你会怎么做?
另外,你将如何创建一个像这样的函数check({ ... });
它不依赖于任何特定的 jquery 选择器,而是可以像常规函数一样调用,如下所示:
displayRandomNumber({ min: 0, max: 100, displayAt: 'someID'});
// so no jquery selector in front.
感谢您的帮助!
如果你想使用:
check({ timer: 1000, redo: 4000, displayAt: 'someID' });
使用 jquery.fn.extend 你的函数将像这样声明:
check: function(options) {
// Get the timer value
var timerValue = options.timer;
// Get the redo value
var redoValue = options.redo;
...
}
独立的话,它看起来像这样:
function check(options) {
// Get the timer value
var timerValue = options.timer;
// Get the redo value
var redoValue = options.redo;
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)