日期:2014-05-16 浏览次数:20414 次
<div class="box" onmouseover="addBorderColor()" onmouseout="removeBorderColor()">BOX1</div> <div class="box" onmouseover="addBorderColor()" onmouseout="removeBorderColor()">BOX2</div> <div class="box" onmouseover="addBorderColor()" onmouseout="removeBorderColor()">BOX3</div> <div class="box" onmouseover="addBorderColor()" onmouseout="removeBorderColor()">BOX3</div>
function addBorderColor(){ $(this).css("border","1px solid #CCC"); } function removeBorderColor(){ $(this).css("border","none"); }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>new document</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("div.box").hover( function(){ $(this).css("border", "1px solid #ccc"); }, function(){ $(this).css("border", "none"); } ); }); </script> </head> <body> <div class="box" >BOX1</div> <div class="box" >BOX2</div> <div class="box" >BOX3</div> <div class="box" >BOX3</div> </body> </html>
------解决方案--------------------
按你的思路修改的:
<div class="box" onmouseover="addBorderColor(this)" onmouseout="removeBorderColor(this)">BOX1</div> function addBorderColor(obj){ $(obj).css("border","1px solid #CCC"); } function removeBorderColor(obj){ $(obj).css("border","none"); }