<script>
var isClick = false;
var bgColor = 'red';function _click(obj){
isClick = true;
obj.bgColor = bgColor;
}function _over(obj){
obj.bgColor = bgColor;
}function _out(obj){
if(!isClick){
obj.bgColor = "";
}
}
</script>
<table>
<tr>
<td onmouseover="_over(this);" onmouseout="_out(this);" onClick="_click(this);">dfasfdasfsafs</td>
</tr>
</table>
var isClick = false;
var bgColor = 'red';function _click(obj){
isClick = true;
obj.bgColor = bgColor;
}function _over(obj){
obj.bgColor = bgColor;
}function _out(obj){
if(!isClick){
obj.bgColor = "";
}
}
</script>
<table>
<tr>
<td onmouseover="_over(this);" onmouseout="_out(this);" onClick="_click(this);">dfasfdasfsafs</td>
</tr>
</table>
解决方案 »
- 求助。当鼠标点空白处时,取消当前事件。。
- javascript如何恢复<span>或<div>默认/初始化时的innerHTML
- javascript生成input框的按钮添加事件问题
- 寻求支持java,c#等的关键字高亮显示 脚本
- 求一个JS倒计时代码
- 关于Jcrop的问题
- ie9 body onload 不执行 求高人指点 送100
- 问一下CSDN主页上面哪两个广告的效果如何实现?
- netscape中怎么通过URL来打开一个服务器上的eml文件并自动对它解码并进行显示
- 我在HTML中嵌入了动态生成行的JAVASCRIPT语句,生成内容后为什么在源带码中看不见???
- 100急求一个简单问题!
- js切换不同的flash(非图片)
<head>
</head>
<body><table id="table">
<tr>
<td onmouseover="mouseover()" onmouseout="mouseout()" onclick="aclick()">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td>
</tr>
</table><script language="javascript">
function mouseover()
{
event.srcElement.bgColor="red";
}
function mouseout()
{
event.srcElement.bgColor="";
} function aclick()
{
event.srcElement.onmouseover=null;
event.srcElement.onmouseout=null
}</script>
</body>
</html>
谢谢各位的帮助!
如:
<td>1</td><td>2</td><td>3</td>
当鼠标放在1或2或3上面时,分别显示背景,当鼠标移开1或2或3时,隐藏背景
当鼠标单击1或2或3时,分别只停留在某一个TD上,其它TD背景隐藏,不知道大家明白了没有?
INPUT.FocuSelect {
gotfocu: expression(onfocus=function(){
if(this.type!="button"&&this.type!="submit"&&this.type!="reset") this.select();}
)
}</style>我知道你说的是这种效果,不过css实现的话,会有很多重复执行问题,特别是mousemove,条件不好设置,所以造成严重的效率问题。
<!--
TD.Edit {
mouse: expression(
onmouseover=function(){this.style.background='#CCCCCC'},
onmouseout=function(){this.style.background=''},
);
key: expression(
onkeypress=function(){this.innerText+=event.keyCode;},
);
}
-->
</style>
<table border="1">
<tr>
<td width="30" height="30" onkeypress="" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
</table>点击不变要用static
onkeypress=function(){this.innerText+=event.keyCode;},
);这个不要
<!--
TD.Edit {
mouse: expression(
onmouseover=function(){this.style.background='#CCCCCC'},
onmouseout=function(){this.style.background=''}
)
}
-->
</style>
<table border="1">
<tr>
<td width="30" height="30" onkeypress="" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
<td width="30" height="30" class="Edit"> </td>
</tr>
</table>用这个方式可以,不过全局变量我没试过。
var tdcur="";function enterstr(){
var td=document.getElementById(tdcur);
td.innerText+=String.fromCharCode(event.keyCode);
}
document.onkeypress=enterstr;
</script>
<style type="text/css">
<!--
TD.Edit {
mouse: expression(
onmouseover=function(){this.style.background='#CCCCCC'},
onmouseout=function(){if(tdcur!=this.id) this.style.background=''},
onclick=function(){var tdPrev=document.getElementById(tdcur);if(tdPrev!=null)tdPrev.style.background='';tdcur=this.id;this.style.background='#CCCCCC'}
)
}
-->
</style>
<table border="1">
<tr>
<td id=td1 width="30" height="30" onkeypress="" class="Edit"> </td>
<td id=td2 width="30" height="30" class="Edit"> </td>
<td id=td3 width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td id=td4 width="30" height="30" class="Edit"> </td>
<td id=td5 width="30" height="30" class="Edit"> </td>
<td id=td6 width="30" height="30" class="Edit"> </td>
</tr>
<tr>
<td id=td7 width="30" height="30" class="Edit"> </td>
<td id=td8 width="30" height="30" class="Edit"> </td>
<td id=td9 width="30" height="30" class="Edit"> </td>
</tr>
</table>可以使用全局变量