2009-06-20 5 views
0

나는 내용이 emapty 인 경우 초점에있는 텍스트 상자의 배경 이미지를 변경하고 이전 이미지 ob을 유지하는 다음 스크립트를 사용합니다. 이미지는 워터 마크와 유사합니다. 프로토 타입 자바 스크립트 라이브러리.jQuery 대체 Prototype 메서드

<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> 

지금 난 내 page.I 멀리 내 페이지에서 프로토 타입을 먹고 싶어에서 이걸의 jQuery를 교체 이미 jQuery를 사용하고 갖고 싶어.

당신은 초점 흐림 이벤트 요소의 배경 이미지 CSS 속성을 조작 할 수

답변

2

:

$(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+')'); 
     } 
    }); 
});