2010-06-18 3 views
3

jQuery의 $.live() 기능으로 테이블 행을 클릭 할 수있게 만들고 있습니다.
Chrome, Firefox 및 데스크톱 Windows Safari에서도 완벽하게 작동하지만 iPhone에서는 작동하지 않습니다.
$.bind()은 어디에서나 작동하지만 분명히 다른 기능을 사용하고 싶습니다.

아무도 왜 작동하지 않으며 어떻게 해결할 수 있습니까?
아래의 예제 코드. 이 코드

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<title>test</title> 
<meta charset="utf-8" /> 
<meta name="viewport" content="user-scalable=no,width=device-width" /> 
<meta name="apple-mobile-web-app-capable" content="yes" /> 
<style type="text/css">table { width: 100%; border-collapse: collapse; } table tr {  background: #eee; } table td { padding: 10px; border-top: 1px solid #ccc; }</style> 
<script type="text/javascript" src="http://jquery.com/src/jquery-latest.pack.js">  </script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    /* $.bind() works */ 
    /* 
    $('table').find('tr').bind('click', function() { 
    alert($(this).text()); 
    }); 
    */ 
    /* $.live() doesn't */ 
    $('table').find('tr').live('click', function() { 
    alert($(this).text()); 
    }); 
}); 
</script> 
</head> 
<body> 
<table> 
    <tbody> 
    <tr><td>words are flying out \ </td><td>like endless rain into a paper cup</td></tr> 
    <tr><td>they slither while they pass \ </td><td>they slip away across the    universe</td></tr> 
    </tbody> 
</table> 
</body> 
</html> 

답변

1

하나의 문제는 당신이 .live 잘못 사용하고 있다는 것입니다 - 그것이 선택에 직접 호출해야 다음 specs에서

$('table tr').live(/* ... */) 

:

DOM 탐색 방법 .live()에 보낼 요소를 찾는 데 완전히 지원되지 않습니다. 오히려, .live() 메소드는 항상

다음, jQuery를 1.4.2에, 아마 더 나은

사용하기 위해 선택 후 직접 호출해야 delegate :

$('table').delegate('tr', 'click', function(){/* ... */}); 
관련 문제