日期:2014-05-16  浏览次数:20311 次

想用JS实现以下效果!!!!请帮助!!
我想实现这样一种效果就是当鼠标放上去时显示背景,移开时隐藏背景,当单击时背景保持不变,怎么实现??

<td> sdfdfsdf </td>

当鼠标放在TD上时显示背景,移开时背景隐藏,当单击时背景就保持不变了,不管鼠标是否移开,即便移开背景依然保持

------解决方案--------------------
<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>
------解决方案--------------------
<html>
<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>

------解决方案--------------------
<script language= "javascript ">
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 "> &nbsp; </td>
<td id=td2 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
<td id=td3 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
</tr>
<tr>
<td id=td4 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
<td id=td5 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
<td id=td6 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
</tr>
<tr>
<td id=td7 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
<td id=td8 width= "30 " height= "30 " class= "Edit "> &nbsp; </td>
<td id=td9 width= "30 " height= &