2012-01-26 57 views
0

嗨我试图将焦点设置为选项卡时的选项卡。我遇到的问题是,当我在按钮的背景图像中添加焦点颜色时,图像周围没有显示,但如果我删除图像,按钮效果很好。当它具有焦点并将其重置为模糊时,如何在按钮周围放置边框?将焦点设置为选项卡上的按钮

<html> 
<head> 

<script type="text/javascript" src="jquery-1.3.2.min.js"></script> 


<script type="text/javascript"> 

$(document).ready(function() { 
    $('button:button').focus(function(){ 
    $(this).css({'background-color' : 'red'}); 
    }); 
    $('button:button').blur(function(){ 
    $(this).css({'background-color' : 'lightgreen'}); 
    }); 
}); 
</script> 


</head> 
<body> 
    <button type='button' id='btnSubmit' style="background-image:  
    urlbuttonBackground.gif);"  >button</button> 
</body> 
</html> 
+0

jQuery的1.3?这很古老。 – ThiefMaster

回答

1

您可以在CSS类中定义这些样式,然后应用上focus类,并删除它blur。尝试这个。

button

<button type='button' id='btnSubmit'>button</button> 

的CSS删除内联样式(定义样式根据自己的需要)

button{ 
    background: lightgreen; 
} 
.focusBg{ 
    background: ulr('urlbuttonBackground.gif'); 
    border: 1px solid red; 
} 

JS

$(document).ready(function() { 
    //Since the button has an id, you can use id selector 
    $('#btnSubmit').focus(function(){ 
      $(this).addClass('focusBg'); 
    }).blur(function(){ 
      $(this).removeClass('focusBg'); 
    }); 
}); 
+0

非常感谢 –

相关问题