javascript当中documentonkeydown的⽤法例 2.2(documentKeypressIEFF.html)
当系统看见这句话:keydown = handleKeypress; 以后,当你按keydown时,系统⾃然就调⽤:handleKeypress(event)。⽽且传进来event参数。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</HEAD>
<script>
function handleKeypress(event)
{
/*⽕狐⽤event所以window.event为undefined,ie正相反,所以event || window.event可以兼容*/
alert("event is "+event +"window.event is "+window.event);
alert(111||undefined);//任何数和undefined做||,为原值。
var event = event || window.event;
if (window.navigator.userAgent.indexOf("MSIE") >= 1)
{
var key = event.keyCode;
alert("Key: " + String.fromCharCode(key) + "\nCharacter code: " + key + ".");
}
else if ( window.navigator.userAgent.indexOf("Firefox") >= 1)
{ var key = event.which;//event.which获取按下的键盘按键Unicode值:
>indexof的用法javascript
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论