gpt4 book ai didi

javascript - D3 键盘事件返回超链接

转载 作者:行者123 更新时间:2023-11-27 22:52:19 24 4
gpt4 key购买 nike

我正在尝试在我的网站上进行一种“按键导航”:如果按左箭头,我将返回到上一页,如果按右箭头,我将转到下一页。我已经这样做了,“console.log(“keydown”)”有效,但函数返回无效。

d3.select("body")
.on("keydown", function(e) {
console.log("keydown");
//return "line_chart.html";
if(e == 37) { // left
console.log("left");
return "line_chart1.html";
}
else if(e == 39) { // right
console.log("right");
return "line_chart2.html";
}
});

最佳答案

而不是

.on("keydown", function(e) { //e is coming UNDEFINED
console.log("keydown");
//return "line_chart.html";
if(e == 37) { // left i found e as undefined

我使用d3.event.keycode获得了键码,它的工作原理如下:

d3.select("body")
.on("keydown", function(e) {
console.log("keydown");
//return "line_chart.html";
if(d3.event.keycode == 37) { // left
console.log("left");
return "line_chart1.html";//this return will not do anything
}
else if(d3.event.keycode == 39) { // right
console.log("right");
return "line_chart2.html";//this return will not do anything
}
});

编辑

d3.select("body")
.on("keydown", function(e) {
console.log("keydown");
//return "line_chart.html";
if(d3.event.keyCode == 37) { // left
console.log("left");
SOME_FUNCTION("line_chart1.html");
}
else if(d3.event.keyCode == 39) { // right
console.log("right");
SOME_FUNCTION("line_chart2.html");
}
});

关于javascript - D3 键盘事件返回超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37964233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com