我不确定为什么这不起作用,我在网上阅读的所有文章都使它看起来应该起作用。好吧,这是我的 html 代码:()
<!doctype html>
<html>
<head>
<script src = "http://code.jquery.com/jquery-latest.min.js" type = "text/javascript"></script>
<script src = "showmotto.js" type = "text/javascript"> </script>
</head>
<body>
<table>
<?php
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$sth = $pdo->query('SELECT * from users');
$sth->setFetchMode(PDO::FETCH_ASSOC);
while( $row = $sth->fetch() )
{
echo "<tr><td class = \"users\" data-motto = '{$row['motto']}' >{$row['username']}</td></tr>";
}
$pdo = null;
?>
</table>
</body>
</html>
这里是 show-motto.js。我的目标是在用户将鼠标悬停在表格上时使用 data-motto 中的信息提醒用户。但是我还没有走那么远,因为由于某种原因,鼠标悬停事件不起作用
$('td.users').live('mouseover', function()
alert(0);
});
我也试过 $('.users') 但它也不起作用。
我究竟做错了什么?