JQuery UI(手风琴),在初始化时打开活动选项卡

时间:2016-03-16 14:42:51

标签: javascript jquery html opencart

我在网站上有一个基本的sidenav菜单,根据h3>这有父项和子项。 jQuery文档推荐的div结构。

我需要根据它所在的页面打开“活动”标签。 CMS已经将“活动”类应用于h3,但是我成功打开(或激活)选项卡的唯一方法是使用h3的索引,即0,1,2,3。由于我是一名新手,我一直在努力获得“活跃”h3的索引,因为大多数教程都展示了在有序列表中获取li元素索引的示例。

我的HTML看起来像这样:

<div id="accordion">
    <h3>Menu 1</h3>
    <div>sub-menu</div>
    <h3>Menu 2</h3>
    <div>sub-menu</div>
    <h3 class="active">Menu 3</h3>
    <div>sub-menu</div>
    <h3>Menu 4</h3>
    <div>sub-menu</div>
</div>

现在我知道第3个h3是索引2所以如果我需要将该标签硬编码为打开它很容易,但我需要根据哪个h3元素得到索引(没有固定的数量)有“活跃”类。

CMS是OpenCart,JQuery版本是1.10.1

2 个答案:

答案 0 :(得分:0)

阅读您的问题,不应该需要知道索引才能打开它,具体取决于页面。只需在jQuery中使用css选择器定位活动的H3,然后对其执行所需的操作,如下所示;

 $('.accordion h3.active').next().slideDown();

示例代码,您可能需要使用.next()打开子菜单,例如;

SELECT td.Area,
sum(COALESCE(se.ErectionFootage,0)) AS CountErectionFootage, sum(COALESCE(sb.BoltUpCount,0)) AS CountBoltUp, sum(COALESCE(sw.WeldCount,0)) AS CountWeld, sum(COALESCE(st.TrimActivitiesCount,0)) AS CountTrimActivities, sum(COALESCE(sm.MiscActivitiesCount,0)) AS CountMiscActivities, sum(COALESCE(ssu.SupportCount,0)) AS CountSupports,
(sum(COALESCE(sb.BoltUpCount, 0)) + sum(COALESCE(sw.WeldCount, 0))) AS CountBasicConnection,
(sum(COALESCE(st.TrimActivitiesCount, 0)) + sum(COALESCE(sm.MiscActivitiesCount, 0)) + sum(COALESCE(ssu.SupportCount, 0))) AS CountBasicTrimActivities,

sum(COALESCE(se.ErectionHours,0)) AS HoursErection, sum(COALESCE(sb.BoltUpHours,0)) AS HoursBoltUp, sum(COALESCE(sw.WeldHours,0)) AS HoursWeld, sum(COALESCE(st.TrimHours,0)) AS HoursTrim, sum(COALESCE(sm.MiscHours,0)) AS HoursMisc, sum(COALESCE(ssu.SupportHours,0)) AS HoursSupports,
(sum(COALESCE(sb.BoltUpHours, 0)) + sum(COALESCE(sw.WeldHours, 0))) AS HoursBasicConnection,
(sum(COALESCE(st.TrimHours, 0)) + sum(COALESCE(sm.MiscHours, 0)) + sum(COALESCE(ssu.SupportHours, 0))) AS HoursBasicTrimActivities,

sum(COALESCE(er.InstalledFootage,0)) AS InstalledFootage, sum(COALESCE(er.InstalledBoltUps,0)) AS InstalledBoltUps, sum(COALESCE(er.InstalledWelds,0)) AS InstalledWelds,
sum(COALESCE(er.InstalledBasicConnections,0)) AS InstalledBasicConnections, 

sum(COALESCE(er.InstalledTrim,0)) AS InstalledTrim, sum(COALESCE(er.InstalledMisc,0)) AS InstalledMisc, sum(COALESCE(er.InstalledSupports,0)) AS InstalledSupports,
sum(COALESCE(er.InstalledBasicTrim,0)) AS InstalledBasicTrim,

TRUNCATE(sum(COALESCE(er.EarnedErectionHours,0)),2) AS EarnedErectionHours, 
TRUNCATE(sum(COALESCE(er.EarnedBoltUpHours, 0)),2) AS EarnedBoltUpHours,
TRUNCATE(sum(COALESCE(er.EarnedWeldHours,0)),2) AS EarnedWeldHours,
TRUNCATE(sum(COALESCE(er.EarnedTrimHours,0)),2) AS EarnedTrimHours,
TRUNCATE(sum(COALESCE(er.EarnedSupportHours,0)),2) AS EarnedSupportHours,
TRUNCATE(sum(COALESCE(er.EarnedMiscHours,0)),2) AS EarnedMiscHours,

TRUNCATE((sum(COALESCE(er.EarnedBoltUpHours, 0)) + sum(COALESCE(er.EarnedWeldHours,0))),2) AS EarnedBasicConnectHours,
TRUNCATE((sum(COALESCE(er.EarnedTrimHours, 0)) + sum(COALESCE(er.EarnedMiscHours,0)) + + sum(COALESCE(er.EarnedSupportHours,0))),2)AS EarnedBasicTrimHours,

(sum(COALESCE(se.ErectionFootage,0)) - sum(COALESCE(er.InstalledFootage,0))) AS RemainingFootage,
(sum(COALESCE(sb.BoltUpCount,0)) - sum(COALESCE(er.InstalledBoltUps,0))) AS RemainingBoltUps,
(sum(COALESCE(sw.WeldCount,0)) - sum(COALESCE(er.InstalledWelds,0))) AS RemainingWelds, 
((sum(COALESCE(sb.BoltUpCount,0)) + sum(COALESCE(sw.WeldCount,0))) - (sum(COALESCE(er.InstalledBoltUps,0)) + sum(COALESCE(er.InstalledWelds,0)))) AS RemainingBasicConnections, 

(sum(COALESCE(st.TrimActivitiesCount,0)) - sum(COALESCE(er.InstalledTrim,0))) AS RemainingTrimActivities,
(sum(COALESCE(ssu.SupportCount,0)) - sum(COALESCE(er.InstalledSupports,0))) AS RemainingSupports,
(sum(COALESCE(sm.MiscActivitiesCount,0)) - sum(COALESCE(er.InstalledMisc,0))) As RemainingMiscActivities,
((sum(COALESCE(st.TrimActivitiesCount,0)) + sum(COALESCE(sm.MiscActivitiesCount,0)) + sum(COALESCE(ssu.SupportCount,0))) - (sum(COALESCE(er.InstalledTrim,0)) +sum(COALESCE(er.InstalledMisc,0)) + sum(COALESCE(er.InstalledSupports,0)))) AS RemainingBasicTrimActivities,

TRUNCATE((sum(COALESCE(se.ErectionHours,0)) - sum(COALESCE(er.EarnedErectionHours,0))), 2) AS RemainingErectionHours,
TRUNCATE((sum(COALESCE(sb.BoltUpHours,0)) - sum(COALESCE(er.EarnedBoltUpHours,0))),2) AS RemainingBoltUpHours,
TRUNCATE((sum(COALESCE(sw.WeldHours,0)) - sum(COALESCE(er.EarnedWeldHours,0))),2) AS RemainingWeldHours, 
TRUNCATE(((sum(COALESCE(sb.BoltUpHours,0)) + sum(COALESCE(sw.WeldHours,0))) - (sum(COALESCE(er.EarnedBoltUpHours,0)) + sum(COALESCE(er.EarnedWeldHours,0)))),2) AS RemainingBasicConnectionHours, 

TRUNCATE((sum(COALESCE(st.TrimHours,0)) - sum(COALESCE(er.EarnedTrimHours,0))),2) AS RemainingTrimHours,
TRUNCATE((sum(COALESCE(ssu.SupportHours,0)) - sum(COALESCE(er.EarnedSupportHours,0))),2) AS RemainingSupportHours,
TRUNCATE((sum(COALESCE(sm.MiscHours,0)) - sum(COALESCE(er.EarnedMiscHours,0))),2) As RemainingMiscHours,
TRUNCATE(((sum(COALESCE(st.TrimHours,0)) + sum(COALESCE(sm.MiscHours,0)) + sum(COALESCE(ssu.SupportHours,0))) - (sum(COALESCE(er.EarnedTrimHours,0)) +sum(COALESCE(er.EarnedMiscHours,0)) + sum(COALESCE(er.EarnedSupportHours,0)))),2) AS RemainingBasicTrimHours
,sum(COALESCE(tq.HydroHours, 0)) AS HoursHydro



FROM trackerDetails td
	JOIN trackerQuantities tq
		ON tq.ID = td.ID
	LEFT JOIN (SELECT tq.ID, ss.PSAActivityID, at.ActivityType, 
TRUNCATE(sum(COALESCE((tq.EstimatedHours/tq.TakeOffQuantity*(se.ErectionLengthSpool1 + se.ErectionLengthSpool2 + se.ErectionLengthSpool3 + se.ErectionLengthSpool4 + se.ErectionLengthSpool5 + se.ErectionLengthSpool6)),0)),2) AS EarnedErectionHours,
TRUNCATE(sum(COALESCE((tq.EstimatedHours/tq.TakeOffQuantity*sb.BoltUpInstalled), 0)),2) AS EarnedBoltUpHours,
TRUNCATE(sum(COALESCE((tq.EstimatedHours/tq.TakeOffQuantity*sw.WeldInstalled),0)),2) AS EarnedWeldHours,
TRUNCATE(sum(COALESCE((tq.EstimatedHours/tq.TakeOffQuantity*TrimInstalled),0)),2) AS EarnedTrimHours,
TRUNCATE(sum(COALESCE((tq.EstimatedHours/tq.TakeOffQuantity*SupportInstalled),0)),2) AS EarnedSupportHours,
TRUNCATE(sum(COALESCE((tq.EstimatedHours/tq.TakeOffQuantity*MiscInstalled),0)),2) AS EarnedMiscHours,

sum(COALESCE((se.ErectionLengthSpool1 + se.ErectionLengthSpool2 + se.ErectionLengthSpool3 + se.ErectionLengthSpool4 + se.ErectionLengthSpool5 + se.ErectionLengthSpool6),0)) AS InstalledFootage,

sum(COALESCE(sb.BoltUpInstalled,0)) AS InstalledBoltUps, 
sum(COALESCE(sw.WeldInstalled,0)) AS InstalledWelds,
(sum(COALESCE(sb.BoltUpInstalled,0)) + sum(COALESCE(sw.WeldInstalled,0))) AS InstalledBasicConnections, 

sum(COALESCE(st.TrimInstalled,0)) AS InstalledTrim,
sum(COALESCE(sm.MiscInstalled,0)) AS InstalledMisc,
sum(COALESCE(ssu.SupportInstalled,0)) AS InstalledSupports,
(sum(COALESCE(st.TrimInstalled,0)) + sum(COALESCE(sm.MiscInstalled,0)) + sum(COALESCE(ssu.SupportInstalled,0))) AS InstalledBasicTrim

FROM SubmissionStatus ss
	JOIN PSA.REF_ActivityTypes at
		ON at.ID = ss.ActivityType
	        
	JOIN SubsDetails sd
		ON sd.SubmissionID = fk_SubmissionId
        
	LEFT JOIN SubsErection se
		ON se.ID = ss.ActivityRowId AND ss.ActivityType = 11
	
    LEFT JOIN (SELECT sb.ID, 1 AS BoltUpInstalled
				FROM SubsBoltUp sb) sb
		ON sb.ID = ss.ActivityRowId AND ss.ActivityType = 21
        
	LEFT JOIN (SELECT sw.ID, 1 AS WeldInstalled
				FROM SubsWeld sw) sw
		ON sw.ID = ss.ActivityRowId AND ss.ActivityType = 22

    LEFT JOIN (SELECT st.ID, st.TrimQuantity AS TrimInstalled
				FROM SubsTrim st) st
		ON st.ID = ss.ActivityRowId AND ss.ActivityType = 31  
        
	LEFT JOIN (SELECT ssu.ID, 1 AS SupportInstalled
				FROM SubsSupports ssu) ssu
		ON ssu.ID = ss.ActivityRowId AND ss.ActivityType = 32        
        
    LEFT JOIN (SELECT sm.ID, 1 AS MiscInstalled
				FROM SubsMisc sm) sm
		ON sm.ID = ss.ActivityRowId AND ss.ActivityType = 91


	
    LEFT JOIN (SELECT tq.ID, tq.TakeOffQuantity, tq.EstimatedHours 
				FROM trackerQuantities tq) tq
		ON tq.ID = ss.fk_BidIDAssigned
        
WHERE fk_ActivityStatus IN (5)
GROUP BY tq.ID) er
		ON er.ID = td.ID
    
    LEFT JOIN (SELECT tq.ID, tq.TakeOffQuantity AS  ErectionFootage, tq.EstimatedHours AS ErectionHours
				FROM trackerQuantities tq
					JOIN trackerDetails td
						ON td.ID = tq.ID
				WHERE PipingActivityType = 'PE') se
		ON se.ID = td.ID

	LEFT JOIN (SELECT tq.ID, tq.TakeOffQuantity AS  BoltUpCount, tq.EstimatedHours AS BoltUpHours
				FROM trackerQuantities tq
					JOIN trackerDetails td
						ON td.ID = tq.ID
				WHERE PipingActivityType = 'BU') sb
		ON sb.ID = td.ID
        
	LEFT JOIN (SELECT tq.ID, tq.TakeOffQuantity AS  WeldCount, tq.EstimatedHours AS WeldHours
				FROM trackerQuantities tq
					JOIN trackerDetails td
						ON td.ID = tq.ID
				WHERE ECT = 'C' AND PipingActivityType != 'BU') sw
		ON sw.ID = td.ID
        
	LEFT JOIN (SELECT tq.ID,  tq.TakeOffQuantity AS  TrimActivitiesCount, tq.EstimatedHours AS TrimHours
				FROM trackerQuantities tq
					JOIN trackerDetails td
						ON td.ID = tq.ID
				WHERE ECT = 'T' AND PipingActivityType != 'MISC') st
		ON st.ID = td.ID

	LEFT JOIN (SELECT tq.ID, tq.TakeOffQuantity AS  SupportCount, tq.EstimatedHours AS SupportHours
				FROM trackerQuantities tq
					JOIN trackerDetails td
						ON td.ID = tq.ID
				WHERE PipingActivityType = 'S') ssu
		ON ssu.ID = td.ID
        
	LEFT JOIN (SELECT tq.ID, tq.TakeOffQuantity AS  MiscActivitiesCount, tq.EstimatedHours AS MiscHours
				FROM trackerQuantities tq
					JOIN trackerDetails td
						ON td.ID = tq.ID
				WHERE PipingActivityType = 'MISC') sm
		ON sm.ID = td.ID
        
GROUP BY td.Area

ORDER BY td.Area

答案 1 :(得分:0)

如果您因任何原因想要找​​到活动h3的索引,可以使用以下代码

$("#accordion h3.active").index()/2