2009-06-20 88 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+')'); 
     } 
    }); 
});