이 어떻게 사업부에 영향을 jQuery를 이것과 클래스를 사용합니까 사업부에 영향을 jQuery를 이것과 클래스를 사용 않는 나는 그 작품을 만들었다. 나는 결과를 지우는 결과를 얻는 것으로 어려움을 겪고있다. 사용자가 결과 나 검색 창 바깥을 클릭 할 때만 그렇다. 다음은 검색 창에서 IN 또는 결과 div를 클릭해도 결과가 지워지는 경우를 제외하고는 작동합니다. (나는 문제가 if 문에서 "이"참조 관련이 있다고 상상한다.) 나는 또한 시도어떻게 사업부 외부 사용자가 클릭</p> <p>내가 검색이있을 때
$('#searchbox').keyup(function(){
$.post("remote.php",{'func':'contactsearch','partial':this.value},function(data){
$("#results").html(data);
// erase the results when user clicks outside the search
$('body').click(function(){
if (!$(this).hasClass('nd_search')) { // erases results even when clicked inside result - why?
$("#results").html('');
$('body').unbind('click'); // remove event handler. add again when results shown.
}
});
});
});
});
<div class="nd_search">
<input id="searchbox" type="text" class="nd_search"/>
<div id="results" class="nd_search"></div>
</div>
:
$('body').click(function(event){
if (!$(event.target).hasClass('nd_search')) { ...
을 둘째로, 차라리에만 포함 DIV에 클래스를 가질 것 . if 문을 어떻게 변경합니까?
나는이 주제에 관해서 다른 게시물을 보았는데, 이것은 나에게 이것을 멀리 가지고있다. 나는
감사. 시체를 클릭하면 어디에서 언 바인드 하시겠습니까? 또는 당신을 원할 것입니다. 하나의 창에서 두 가지 이상의 검색을 수행 할 것입니다. – sdfor
당신은'event.stopPropagation();'또는'.end()'논리를 사용할 수 있습니다. 나는 적용하지 않았습니다. 참고 번호 – diEcho