我已经安装了一个灯箱插件,如果我的应用程序的其他部分的功能无需重新编码单独的模块,我想重新启动一些,因为它有点多余,所以可以重用/共享一些功能来自像这样的图书馆的图书馆
http://www.notesfor.net/samples/jquery/notesforlightbox/js/nf.lightbox.js
我的意图是这个灯箱插件已经支持下一个,上一个,关闭等热键......
这是情况......形成lightbox.js ...... 我想将这个特定函数重用于我的应用程序的另一部分
(function($) {
$.fn.lightBox = function(settings) {
.... ...... ...... .....等......
function _keyboard_action(objEvent) {
// To ie
if (objEvent == null) {
keycode = event.keyCode;
escapeKey = 27;
// To Mozilla
} else {
keycode = objEvent.keyCode;
escapeKey = objEvent.DOM_VK_ESCAPE;
}
// Get the key in lower case form
key = String.fromCharCode(keycode).toLowerCase();
// Verify the keys to close the ligthBox
if ((key == settings.keyToClose) || (key == 'x') || (keycode == escapeKey)) {
_finish();
}
// Verify the key to show the previous image
if ((key == settings.keyToPrev) || (keycode == 37)) {
// If we´re not showing the first image, call the previous
if (settings.activeImage != 0) {
settings.activeImage = settings.activeImage - 1;
_set_image_to_view();
_disable_keyboard_navigation();
}
}
// Verify the key to show the next image
if ((key == settings.keyToNext) || (keycode == 39)) {
// If we´re not showing the last image, call the next
if (settings.activeImage != (settings.imageArray.length - 1)) {
settings.activeImage = settings.activeImage + 1;
_set_image_to_view();
_disable_keyboard_navigation();
}
}
}
.... ...... ...... .....等......
};
})(jQuery的);
但是如果我从外面调用:_keyboard_action(objEvent),我会收到错误,那么这样做的正确语法是什么?
答案 0 :(得分:0)
从我对这篇文章的理解(如果我没有被误解),你可以简单地使用
<script src="NameOfJavascriptFile.js" type="text/javascript">
<head>
部分中,然后像普通函数一样调用函数。