2012-01-26 60 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

非常感謝 –

相關問題