我向jquery求援,有一个简单的问题..我想从database..When上列出我悬停在其显示隐藏文本标题上的帖子。与freelancers.com上的示例相同
这是我的代码..
<html>
<head>
<link rel="stylesheet" type="text/css" href="index.css" />
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("tr").mouseover(function(){
$(".neparan").show();
});
$(".neparan").mouseleave(function(){
$(".neparan").hide();
});
});
</script>
</head>
<body>
<table border="1">
<?php
$host = "localhost";
$user = "root";
$lozinka = "";
$baza = "jquery";
mysql_connect($host, $user, $lozinka);
mysql_select_db($baza);
$upit = mysql_query("SELECT * FROM tekst");
while ($red = mysql_fetch_array($upit)) { ?>
<tr class="naslov">
<td>
<?php echo $red["naslov"]; ?>
</td>
</tr>
<tr class="neparan">
<td>
<?php echo $red["tekst"]; ?>
</td>
<td>
<?php echo $red["naslov"]; ?>
</tr>
<?php echo "</br>";
} ?>
</tr>
</table>
</body>
</html>和css文件..
.neparan {display:none;}
.naslov {color:red;}问题是,当我在tr上悬停时,所有的td都显示...
发布于 2012-03-07 00:53:01
使用find()方法很可能会帮助您更好地理解有关搜索元素的上下文
http://api.jquery.com/find/
$(document).ready(function() {
$("tr").mouseover(function() {
/* "this" refers to row being hovered*/
$(this).find(".neparan").show();
});
$(".neparan").mouseleave(function() {
$(this).find(".neparan").hide();
});
}); 发布于 2012-03-07 00:44:20
当鼠标悬停在一个tr上时,您将使用:$(".neparan").show();显示所有的neparan类
更改代码:
$("tr").mouseover(function(){ $(".neparan").show(); }); //
$(".neparan").mouseleave(function(){ $(".neparan").hide(); });至:
$("tr").mouseover(function(){ $(".neparan", this).show(); });
$(".neparan").mouseleave(function(){ $(this).hide(); });我使用了context参数:
jQuery(选择器,上下文)
选择器包含选择器表达式的字符串
上下文-用作上下文的DOM元素、文档或jQuery
https://stackoverflow.com/questions/9588004
复制相似问题