Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按下DIV键以参考某个位置_Javascript_Html_Location Href - Fatal编程技术网

Javascript 按下DIV键以参考某个位置

Javascript 按下DIV键以参考某个位置,javascript,html,location-href,Javascript,Html,Location Href,我知道如何使div在被单击时引用一个位置 <div onclick="location.href='newurl.html';" tabindex="0"><a>Text</a></div> 我不想在其他地方编写代码,比如js文件只需将两个侦听器连接到div,然后在onkeydown中检查按下的键: <div onkeydown="if(event.which===32||event.which===13) location.hre

我知道如何使div在被单击时引用一个位置

<div onclick="location.href='newurl.html';" tabindex="0"><a>Text</a></div>


我不想在其他地方编写代码,比如js文件

只需将两个侦听器连接到
div
,然后在
onkeydown
中检查按下的键:

<div
  onkeydown="if(event.which===32||event.which===13) location.href='newurl.html';"
  onclick="location.href='newurl.html';"
  tabindex="0"
>
    <a>Islam</a>
</div>


.

只需将两个侦听器连接到
div
,然后在
onkeydown
中检查按下的键:

<div
  onkeydown="if(event.which===32||event.which===13) location.href='newurl.html';"
  onclick="location.href='newurl.html';"
  tabindex="0"
>
    <a>Islam</a>
</div>


.

只需将两个侦听器连接到
div
,然后在
onkeydown
中检查按下的键:

<div
  onkeydown="if(event.which===32||event.which===13) location.href='newurl.html';"
  onclick="location.href='newurl.html';"
  tabindex="0"
>
    <a>Islam</a>
</div>


.

只需将两个侦听器连接到
div
,然后在
onkeydown
中检查按下的键:

<div
  onkeydown="if(event.which===32||event.which===13) location.href='newurl.html';"
  onclick="location.href='newurl.html';"
  tabindex="0"
>
    <a>Islam</a>
</div>


.

我不完全确定您想要什么,但可能您正在查找
event.keyCode
。它为您提供按键的代码,您可以轻松地检查
Enter
Space

<div onkeydown="if(event.keyCode==13||event.keyCode==32)location.href='newurl.html'; " onclick="location.href='newurl.html';" tabindex="0">Link</div>
链接

我不完全确定您想要什么,但可能您正在查找
event.keyCode
。它为您提供按键的代码,您可以轻松地检查
Enter
Space

<div onkeydown="if(event.keyCode==13||event.keyCode==32)location.href='newurl.html'; " onclick="location.href='newurl.html';" tabindex="0">Link</div>
链接

我不完全确定您想要什么,但可能您正在查找
event.keyCode
。它为您提供按键的代码,您可以轻松地检查
Enter
Space

<div onkeydown="if(event.keyCode==13||event.keyCode==32)location.href='newurl.html'; " onclick="location.href='newurl.html';" tabindex="0">Link</div>
链接

我不完全确定您想要什么,但可能您正在查找
event.keyCode
。它为您提供按键的代码,您可以轻松地检查
Enter
Space

<div onkeydown="if(event.keyCode==13||event.keyCode==32)location.href='newurl.html'; " onclick="location.href='newurl.html';" tabindex="0">Link</div>
链接