Jquery如何选择现在mouseover的div的子元素 有很多class(假设是a)相同的div,每个div下又有相同class(假设是b)的span,如何才能选择当前div的span呢?查到一种方法是$(".a").mouseover(function(){$(".b",this).css(...)})我用来不管用啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script><script type="text/javascript">$(document).ready( function() { $("div.a span.b").mouseover( function() { $(this).css("background-color", "red"); });});</script></head><body><div class="a"><span class="b">111</span></div><div class="a"><span class="b">222</span></div></body></html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(".a").mouseover(function () { $(this).find('.b').css({color:'red'}); }); }); </script></head><body><body><div class="a" style="border:1px solid red;"><span class="b">111</span><span class="b">222</span></div><div class="a" style="border:1px solid green;"><span class="b">333</span><span class="b">444</span></div></body></body></html> $(".a").mouseover(function(){$(this).find("span.b").css(...)}) 哈哈,日,乌龙了。你们没有测试一下我的写法吗?也对的,但是我把那个span写在div外边了。那个写法确实不常见,在stackoverflow上看来的。 知道2个数 求相近的2个数 FCKeditor中一个页面如何使用2个ReplaceTextarea 正则表达式 路径支持中文 求解一个正则的写法,搞定马上结贴 javascript 对象赋值 如何取得这种情况下的窗口对象!!? 菜鸟的烦恼之“文本框篇”^_^ 请教怎么计算字符串字节长度? 求助,关于使用iframe嵌套外部地址导致自己系统页面加载失去响应 网页俄罗斯方块怎么随着浏览器窗口的放大缩小一直保持居中,玩的时候每个方块也保持居中 在线等,马上结贴,求一正则表达式 召唤高手实现网页常见到的代码~~~~~~~~~~~~~~~~
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$("div.a span.b").mouseover( function() { $(this).css("background-color", "red"); });
});
</script>
</head><body>
<div class="a"><span class="b">111</span></div>
<div class="a"><span class="b">222</span></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".a").mouseover(function () {
$(this).find('.b').css({color:'red'});
});
});
</script></head>
<body>
<body>
<div class="a" style="border:1px solid red;">
<span class="b">111</span>
<span class="b">222</span>
</div>
<div class="a" style="border:1px solid green;">
<span class="b">333</span>
<span class="b">444</span>
</div>
</body></body>
</html>
你们没有测试一下我的写法吗?也对的,但是我把那个span写在div外边了。
那个写法确实不常见,在stackoverflow上看来的。