改变bootstrap的颜色" well"在鼠标悬停

时间:2016-01-30 07:33:56

标签: php twitter-bootstrap

我正试图改变" well"在鼠标悬停但无法做到这一点。我一直在尝试使用以下代码:

<script type="text/javascript">
    function ChangeColor(well, highLight)
    {
    if (highLight)
    {
      well.style.backgroundColor = '#dcfac9';
    }
         }
</script>
PHP:

echo "  <div class=\"well\" onmouseover=\"ChangeColor(this, true);\"\n"; 
echo " onmouseout=\"ChangeColor(this, false);\"> \n"; 
echo "something";
echo "  </div>\n"; 

上面的代码在鼠标悬停时很好地改变了颜色,但它正在穿过&#34; well&#34;的区域。请帮忙解决。

4 个答案:

答案 0 :(得分:2)

<link rel="stylesheet"  href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>


<div class="well">
	 <p>
     This is a well content
   </p>
</div>


<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script>
  $(".well").mouseenter(
    function(){
      $(this).css('background-color','red');
    });
  
   $(".well").mouseleave(
    function(){
      $(this).css('background-color','#f5f5f5');
    });
</script>

答案 1 :(得分:1)

通过JavaScript执行此操作似乎有点矫枉过正。这可以通过使用CSS轻松完成:

.well:default
{
  background-color: #ccc;
}
.well:hover
{
  background-color: #000;
}

答案 2 :(得分:0)

var getDefaultBg    = $(".well").css("background");
$(".well").mouseover(function() {
    $(this).css("background", "#000");
}). mouseout(function() {
    $(this).css("background", getDefaultBg);
});

只需根据您的要求使用它。

答案 3 :(得分:0)

那是我想要的剧本:

<script>
$(document).ready(function(){
    $(".well").mouseenter(function(){
        $(this).css("background-color", "#efefef");
    });
    $(".well").mouseleave(function(){
        $(this).css("background-color", "#f5f5f5");
    });
});
</script>