2011-12-02 3 views
0

jQuery의 blur() 기능이 작동하지 않습니다. 입력 값이 저장 되더라도 표시되지 않습니다. 아무도 그 이유를 말할 수 있습니까? 나도 행운과 함께 on('blur', function(){});를 시험해 보았다.jQuery 흐림 효과 없음

$('form').each(function() { 
    $(this).find(':input') 
     .not('input[type=submit], input[type=hidden]') 
     .each(function() { 

     if (!($.trim($(this).val()))) { 
      if ($(this).attr('data-placeholder')) { 
       putPlaceholder(this); 
      } 
     } 
     $(this).blur(function() { 
      if (!($.trim($(this).val()))) { 
       putPlaceholder(this); 
      } 
     }); 
    }); 
}); 
+0

흐림이 제대로 http://jsfiddle.net/gchoken/aswXV/ – Gowri

+0

를 트리거링이 같은 뭔가를 찾고 계십니까? http://jsfiddle.net/cMSEJ/2/ –

+0

감사합니다.하지만 원격 서버에서 실행할 때 작동하지 않습니다. 행운을 빌어 디버깅하려했습니다. 내가 다른 방법으로 쓸 수 있을지 궁금 해서요 – user1075529

답변

0

나는 완벽하게 여기 근무있어 : http://jsfiddle.net/mmmshuddup/aswXV/3/

var placeholder = "I'm a placeholder"; 
function putPlaceholder(el) { 
    // do something 
    el.value = placeholder; 
    $(el).addClass('placeholder'); 
} 

$('form').each(function() { 
    $(this).find(':input') 
     .not('input[type=submit], input[type=hidden]') 
     .each(function() { 
     if (!$.trim(this.value)) { 
      if ($(this).attr('data-placeholder')) { 
       putPlaceholder(this); 
      } 
     } 

     $(this).focus(function() { 
      if (this.value == placeholder) { 
       this.value = ''; 
      } 
      $(this).removeClass('placeholder'); 
     }).blur(function() { 
      if (!$.trim(this.value)) { 
       putPlaceholder(this); 
      } 
     }); 
    }); 
}); 
+0

고마워요.하지만 이미 저도 해봤어요. 그것은 원격 서버에서 실행할 때 작동하지 않습니다. 나는 정말로 아이디어가 없기 때문에 thers 다른 방법으로 그것을 쓸 수 있는지 궁금 해서요. – user1075529

+0

브라우저에 [firebug] (http://getfirebug.com/)를 설치하고 어떤 오류가 발생했는지 알려주십시오. –

+0

이 중 어떤 것이 브라우저에서 발생합니까? 'onblur' 이벤트 리스너를 제외하고 다른 모든 것이 작동합니까? etc etc –

관련 문제