2009-06-20 90 views
0

我有以下腳本,它將改變焦點上的文本框的背景圖像,並保留以前的圖像ob模糊,如果內容是emapty.The圖像是像水印的東西。這是使用的原型JavaScript庫。jQuery替換原型方法

<div class="searchfield"> 
       <asp:TextBox ID="txtStoreId" runat="server" class="username searchbg"></asp:TextBox> 

       <script type="text/javascript"> 
//<![CDATA[ 
var storeidLabel = new FormLabel('txtStoreId', {image:'../lib/images/store_id.gif', emptyImage:'../lib/images/bg_userpw_notext.gif'}); 
//]]> 
</script> 

    </div> 

現在我想了jQuery更換this.I的我已經使用jQuery在我page.I要採取原型從我的頁面客場有。

回答

2

你可以操縱的重點和模糊事件元素的背景圖像的CSS屬性:

$(document).ready(function(){ 
    var image = '../lib/images/store_id.gif'; 
    var emptyImage = '../lib/images/bg_userpw_notext.gif'; 

    $('#inputId').focus(function(){ 
     $(this).css('background-image', 'url('+image+')'); 
    }); 

    $('#inputId').blur(function(){ 
     if ($(this).val().length === 0){ 
     $(this).css('background-image', 'url('+emptyImage+')'); 
     } 
    }); 
});