2012-11-20 5 views
1

현재 사용자가 클릭 할 때까지 텍스트 상자의 제목을 기본 텍스트로 추가하는 jQuery 함수로 어려움을 겪고 있습니다. 나는이 텍스트를 특정 텍스트 상자에 적용하여 제목 검색을 사용하는 필드에만 적용되도록하기 위해 'title = "Search"로 수정하기를 원합니다. 그러나이 기능이 손상된 것으로 보입니다. 누구든지 아래 기능을 잘못 알고 있습니까?제목을 기반으로 개별 jQuery 요소에 함수 적용

$('input[type="text" title="Search"]').each(function() { 
    this.value = $(this).attr('title'); 
    $(this).addClass('text-label'); 

    $(this).focus(function() { 
     if (this.value == $(this).attr('title')) { 
      this.value = ''; 
      $(this).removeClass('text-label'); 
     } 
    }); 

    $(this).blur(function() { 
     if (this.value == '') { 
      this.value = $(this).attr('title'); 
      $(this).addClass('text-label'); 
     } 
    }); 
}); 
+0

는 "텍스트"제목 = "검색"('입력 [유형 =이 선택 $입니다 ] ') ​​요소를 제공합니까? 또는 0의 길이? –

+0

try $ ('input [type = "text"] [title = "검색"]') 길이 –

답변

6

대신 $('input[type="text"][title="Search"]')을 사용해보세요.

attribute selectors을 jQuery에 사용하는 경우 각 개별 속성을 별도로 작성해야합니다.

업데이트 :

이 특정 사업부 내의 요소에 대해이 작업을하려면, 시도 :

$('#id_of_the_div input[type="text"][title="Search"]')

+0

대단히 감사합니다. ol 'JQuery로 녹슬 었어. – jezzipin

+0

특정 div 내의 특정 요소에만 적용하는 방법을 알고 있습니까? – jezzipin

+1

답변 업데이트보기 – Abhilash

관련 문제