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

求问JS鼠标事件控制<td>标签的背景色
<script type="text/javascript">
function tdMoseon(){
var num = document.getElementById("btId");
num.style.className="tdCsson";
//alert(btId);
}
</script>


tdCsson是CSS样式。

<td id="btId" onmousemove="tdMoseon()">111111</td>

为啥老是没反应。而且不能alert出标签名

求解。或者给出你们的方法。
不用DIV+CSS而用JS是有原因的
谢谢了!!

------解决方案--------------------
HTML code
<style>
.tdCsson{
    background:red;
}
</style>
<body>
<table>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td id="btId" onmouseover="tdMoseon(this)" onmouseout="tdMoseoff(this)">111111</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</table>


<script type="text/javascript">
function tdMoseon(obj){
obj.className="tdCsson";
}

function tdMoseoff(obj){
obj.className="";
}

</script>




</body>