我有这个代码工作,但希望有它,所以当我添加更多表格时,我不必继续添加所有这些部分和格式。
请参阅此处的示例:http: //jsfiddle.net/QtMK2/120/ 我希望单击和切换功能完全按照示例中的方式执行。
我只是希望能够拥有它,这样当我添加更多表时,我不必继续为每个新表添加所有功能。
那么有没有办法做到这一点,所以它使用 (this) 变量只作用于该表?
-JQuery
$(document).ready(function(){
var clicked1 = false; //Used tp keep tr from closing
var clicked2 = false; //Used to Keep tr from closing
//Table1 Hover
$('.ActiveDeMolayTableAwards1 th.AwardsDeMolayHead1') .hover(function(){
if(!clicked1) {
$('.ActiveDeMolayTableAwards1 tr.AwardsDeMolayBody1').toggle();
}});
//Table2 Hover
$('.ActiveDeMolayTableAwards2 th.AwardsDeMolayHead2') .hover(function(){
if(!clicked2) {
$('.ActiveDeMolayTableAwards2 tr.AwardsDeMolayBody2').toggle();
}});
//Table1 Click
$('.ActiveDeMolayTableAwards1 th.AwardsDeMolayHead1').click(function(){
if(!clicked1) {return clicked1 = true;
$('.ActiveDeMolayTableAwards1 tr.AwardsDeMolayBody1').show(); }
if(clicked1) {return clicked1 = false;
$('.ActiveDeMolayTableAwards1 tr.AwardsDeMolayBody1').hide(); }
});
//Table2 Click
$('.ActiveDeMolayTableAwards2 th.AwardsDeMolayHead2').click(function(){
if(!clicked2) {return clicked2 = true;
$('.ActiveDeMolayTableAwards2 tr.AwardsDeMolayBody2').show(); }
if(clicked2) {return clicked2 = false;
$('.ActiveDeMolayTableAwards2 tr.AwardsDeMolayBody2').hide(); }
});
//LOAD CLOSED
$('.ActiveDeMolayTableAwards1 tr.AwardsDeMolayBody1') .hide();
$('.ActiveDeMolayTableAwards2 tr.AwardsDeMolayBody2') .hide();
});