键盘事件修改单元格背景色

有个这样的需求:当按下键盘中的某个按键时,单元格的颜色发生变化。

分析:在页面中捕捉键盘事件,然后在事件中调用js方法改变单元格的颜色。

下面是例子代码

<%@ page language=”java” contentType=”text/html;charset=GBK”%>

<%@taglib uri=”/WEB-INF/runqianReport4.tld” prefix=”report”%>

<html>

<head>

<title>更改颜色测试</title>

<script language=”javascript”>

function change(){

document.getElementById(“report1_A2″).style.backgroundColor=”#FF9900″;

//alert(document.getElementById(“report1_A2″));

}

document.onkeydown=function(){

if(event.altKey)

change();

//alert(“你按alt键了“);

}

function colorChangeBack(){

document.getElementById(“report1_A2″).style.backgroundColor=”#FFFFFF”;

//alert(document.getElementById(“report1_A1″));

}

</script>

</head>

<body>

<report:html name=”report1″

reportFileName=”TEST/changeColor.raq”

/>

<a href=”#” onclick=” colorChangeBack ()”>颜色还原</a>

<body>

</html>

效果如下

alt键之前

alt键之后

本文标签: