我想将此脚本用作函数:
jQuery(function ($) {
var kkeys = [],
login = '76,79,71,73,78'; //login
$(document).keydown(function (e) {
kkeys.push(e.keyCode);
if (kkeys.toString().indexOf(login) >= 0) {
$(document).unbind('keydown', arguments.callee);
return hs.htmlExpand(this, {
contentId: 'highslide-html-loginform',
wrapperClassName: 'mod_cdlogin',
outlineType: 'rounded-white',
align: 'auto',
anchor: 'auto',
dimmingOpacity: 0,
slideshowGroup: 'mod_cdlogin_loginform'
})
}
});
});
所以我可以在我的js部分中使用这段代码来调用另一个文件中的函数,例如codelogin('mycode')
和'mycode'将是76,79,71,73,在这种情况下是78。
我尝试了很多东西但它不起作用。脚本本身工作正常,但我不习惯使用 jQuery,所以这可能是我的问题,我寻找一种方法来做到这一点,但我有点迷失了。任何帮助将不胜感激。
最佳答案
您可以将代码放入函数中并从文件的其他脚本 block 中调用它。
<script>
jQuery(function($){
function YourFunName(myCode){
{
var kkeys = [];
login = myCode;//login
$(document).keydown(function(e)
{
kkeys.push( e.keyCode );
if( kkeys.toString().indexOf( login ) >= 0 )
{
$(document).unbind('keydown',arguments.callee);
return hs.htmlExpand(this, { contentId: 'highslide-html-loginform', wrapperClassName: 'mod_cdlogin', outlineType: 'rounded-white', align: 'auto', anchor: 'auto', dimmingOpacity: 0, slideshowGroup: 'mod_cdlogin_loginform' })
}
});
}
YourFunName('76,79,71,73,78');
});
</script>
关于jquery - 使用 jquery 脚本作为函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13476737/