尝试调用一个函数“clickEvent()”并使用 jQuery 将一个带有箭头键属性的 obj 传递给它。但我没有达到这个功能。这是代码。谢谢。
请注意:我正在分叉现有代码,但将我的 arrowPress 事件添加到其中。因此,如果 (direction != null) 区域,一切都应该保持原样,以便文档准备就绪。
$(document).ready(function() {
$('body').keyup(function(event) {
var direction = null;
// handle cursor keys
if (event.keyCode == 37) {
// slide left
direction = 'prev';
} else if (event.keyCode == 39) {
// slide right
direction = 'next';
}
if (direction != null) {
//alert($('.'+ direction).attr('rel'));
//need to pass the alert above as an obj to the function clickEvent() below.
}
});
}); //end $(document).ready
//function on external .js src
(function($) {
function clickEvent(obj) {
alert(obj.attr("rel"));
}
$.fn.slidingPage = function(options) {
$el = $(this);
}
})(jQuery); //end ext js scr