鼠标滑过改变某模块状态无效,第29行或者 第30-31行 的方法都不行,求解。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../jquery-1.12.2.min.js"></script>
</head>
<body>
<table width="234" height="77" border="1">
  <tr align="center" id="tr1" onMouseOver="over(this.id)" onMouseOut="out(this.id)">
    <td width="52">&nbsp;</td>
    <td width="65">商品</td>
    <td width="95">价格(元)</td>
  </tr>
  <tr align="center" id="tr2" onMouseOver="over(this.id)" onMouseOut="out(this.id)">
    <td>A商场</td>
    <td>S商品</td>
    <td>100</td>
  </tr>
  <tr align="center" id="tr3" onMouseOver="over(this.id)" onMouseOut="out(this.id)">
    <td>B商场</td>
    <td>S商品</td>
    <td>80</td>
  </tr>
</table>
<script>
function over(trname){
    console.log("over")
    $(trname).css({background:"#0000FF",color:"#FFFFFF"})
    //eval(trname).style.backgroundColor="0000FF";
    //eval(trname).style.color="FFFFFF";
}
function out(trname){
    console.log("out")
    eval(trname).style.backgroundColor="FFFFFF";
    eval(trname).style.color="000000";
}
</script>
</body>
</html>


azureks
浏览 1583回答 4
4回答

午后苦咖啡

<script>function over(trname){    console.log("over")    $("#"+trname).css({background:"#0000FF",color:"#FFFFFF"}) ;}function out(trname){    console.log("out")     $("#"+trname).css({background:"#fff",color:"#000"});}</script>

qq_阳光斜影_03450181

直接传 this 进去,还有你十六进制的颜色不写 # 号

瘦驼

jquery选择器和css选择器一致,少了“#”。$("#"+trname).css({"background-color":"#00F","color":"#FFF"});

sakurashine

$('#'+trname).css({background:"#0000FF",color:"#FFFFFF"})这样貌似有用
打开App,查看更多内容
随时随地看视频慕课网APP