在Reader项目中需要加上上下item的快捷键支持。 现在贴下使用到的代码。。
你可以把事件onkeyup写在body中, <body οnkeyup="connectShortKey()" />
如果动态attache的话 是不是用document.body.οnkeyup== fucntion(){}的, 你需要把时间attach到document上。 另外 在firefox 和 ie下取onkeyup事件的keyCode是不一样的。如下。。。
[code] dojo.addOnLoad(function(){
document.οnkeyup=function(event){
var keyCode = -1;
if (dojo.render.html.ie)
keyCode = window.event.keyCode;
else
keyCode = event.keyCode;
if (!isDirectoryPage()){
if (previousPostItem == null){
var ci = getCurrentPostItem()
if (ci!=null){
ci.onclick();
}
return ;
}
var array = getElementsByClass("current_post", null, "div");
var currentItem = null;
if (array.length ==0 ){
return ;
}else{
currentItem = array[0];
}
// user press 'N' key
if (keyCode == 78){
if (currentItem.nextItem != null){
currentItem.nextItem.onclick();
}
}
// user press 'P' key
if (keyCode == 80){
if (currentItem.previousItem != null){
currentItem.previousItem.onclick();
}
}
}
};
});[/code]
你可以把事件onkeyup写在body中, <body οnkeyup="connectShortKey()" />
如果动态attache的话 是不是用document.body.οnkeyup== fucntion(){}的, 你需要把时间attach到document上。 另外 在firefox 和 ie下取onkeyup事件的keyCode是不一样的。如下。。。
[code] dojo.addOnLoad(function(){
document.οnkeyup=function(event){
var keyCode = -1;
if (dojo.render.html.ie)
keyCode = window.event.keyCode;
else
keyCode = event.keyCode;
if (!isDirectoryPage()){
if (previousPostItem == null){
var ci = getCurrentPostItem()
if (ci!=null){
ci.onclick();
}
return ;
}
var array = getElementsByClass("current_post", null, "div");
var currentItem = null;
if (array.length ==0 ){
return ;
}else{
currentItem = array[0];
}
// user press 'N' key
if (keyCode == 78){
if (currentItem.nextItem != null){
currentItem.nextItem.onclick();
}
}
// user press 'P' key
if (keyCode == 80){
if (currentItem.previousItem != null){
currentItem.previousItem.onclick();
}
}
}
};
});[/code]