2013-08-26 4 views
0

저는 기본 양식을 디자인하고 있습니다. 입력 텍스트와 버튼이 있습니다. 내가 버튼을 클릭하면 "입력 텍스트"안에 텍스트가 없으면 "입력 텍스트"에 "x"아이콘이 나타납니다.jquery를 사용하여 요소의 속성을 지우십시오.

jquery로 아이콘을 지정하고 있습니다. 하지만 그것을 어떻게 제거 해야할지 모르겠다. 사용자가 입력 텍스트를 클릭 할 때이 아이콘을 지우고 싶습니다. 여기 내 jquery 코드가 있습니다. 여기

$('#lbl1').click(function() { 
    if ($("#fill").val().length==0) { 
     $("#fill").css({ background: "url(image/cikis.png) no-repeat right"}); 
    } 
}); 

$('#fill').click(function() { 
    //some codes here 
}); 

내 HTML 라인입니다 :

<label id="lbl1">Tıklama </label> 
<input type="text" id="fill" /> 
+0

간단한 팁 : 이미지 대신 기본 텍스트를 사용하려는 경우 html5 자리 표시자를 사용할 수 있습니다. –

+0

아니요, 사용해 보았습니다. 중복이 없습니다. –

+0

@ AliSağırvelioğulları 예 죄송합니다, 질문을 잘못 읽었습니다 –

답변

1
$("#fill").click(function() { 
    $(this).css("background-image", "none"); 
}); 
0

$('#fill').click(function() { 
    $(this).css("background-image", "none"); 
}); 
0

처럼 달성 할 수있는이 작업 예를 참조하십시오

http://jsbin.com/UgIl/1/edit?html,js,output

,369을
$(document).on("focus", "#fill", function (event) { 
     $(this).filter(function() { 
      return $(this).val() == "" 
     }).css("background", "url(http://beoplay.com/resources/sbv-custom/img/linkbuttons/close-icon.png) right no-repeat transparent"); 
    }); 

    $(document).on("blur", "#fill", function (event) { 
     $(this).filter(function() { 
      return $(this).val() == "" 
     }).css("background-image", "none"); 
    }); 
관련 문제