jquery + css - hover with parameter
jquery + css - hover with parameter
<table id="tab">
<tr aaa="one" bbb="ooo"><td>xxx</td><</tr>
<tr aaa="two" bbb="one"><td>xxx</td><</tr>
<tr aaa="three" bbb="one"><td>xxx</td><</tr>
<tr aaa="four" bbb="three"><td>xxx</td><</tr>
</table>
i would like:
如果我将参数aaa="one"的TR悬停,则所有参数bbb="one"的TR的background-color将为红色。
我想使用jquery。
实例:http://jsfiddle.net/syCMN/1/
谢谢你的帮助!
$('tr').hover(function(){
$('tr[bbb="'+$(this).attr('aaa')+'"]').addClass('red');
},function(){
$('tr').removeClass('red');
})
http://jsfiddle.net/syCMN/2/<head>
<script type="text'javascript">
$("#tab tr").hover(function(event){
var param = $(this).attr("aaa");
$("[bbb='"+param+"']").toggleClass("red");
},function(event){
var param = $(this).attr("aaa");
$("[bbb='"+param+"']").toggleClass("red");
});
</script>
</head>
应该这样做:
$(function(){
$('tr[aaa=one]').mouseenter(function(e){
$('tr[bbb=one]').css('background-color', 'red');
});
});
一般来说,这不是一个好主意。由于您的自定义属性,您的代码无法通过任何类型的HTML验证。使用两个类来描述每个<tr>
不是更有意义吗?
$('#tab tr[aaa="one"]').hover(
function(){
$('#tab tr[bbb="one"]')
.css('background-color', 'red');
},
function(){
$('#tab tr[bbb="one"]')
.css('background-color', 'white');
}
);
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- mongodb regex parameter
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Gulp: Jscs with parameter
- Window.Parent.Postmessage with Parameter
- jquery + css - hover with parameter