<分区>
<分区>
在用户按下某个键后移动到新屏幕的代码是什么。例如,我编写了一个空白屏幕,上面写着按任意键开始。
我在网上找了好久,没有找到这样一个不涉及jQuery等的代码。
提前谢谢你。
<script>
//created a variable for instructions
var instructions = '<h1><center>You will see three different symbols appear</center></h1>';
//Created a button
var button = document.createElement('button');
button.innerHTML = 'Click here to Start';
var body = document.getElementsByTagName('body')[0];
body.appendChild(button);
button.addEventListener('click', function(){
if('click'){
document.open(newPage)
}
});
//Pressing a key (space bar in this case) will open up a blank page with the instructions of the experiment
document.addEventListener('keydown',function(e){
if(e.keyCode==32){
document.location.href=('about:blank');
document.write(instructions)
}
});
</script>
最佳答案
最好用EventListener
document.addEventListener('keydown',function(e){
if(e.keyCode==65)//key code for 'a'
location="http://google.com"
})
关键代码列表:http://gcctech.org/csc/javascript/javascript_keycodes.htm
关于javascript - 按下某个键时如何使用 JavaScript/HTML/CSS 加载新页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56433795/