【发布时间】:2011-03-05 14:04:17
【问题描述】:
我正在使用 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>
【问题讨论】:
标签: jquery iphone html-table rows live