我有一个包含列表项的菜单,其 ID 与 div 相关联,每个包含与列表项相关的内容。我试图在单击特定列表项时显示内容。我意识到this
指的是#agency ul li
,但我似乎无法理解如何引用内容 div。
HTML
<ul id="agency">
<li>Select an Agency</li>
<ul>
<li id="agriculture">Department of Agriculture</li>
<li id="commerce">Department of Commerce</li>
<li id="defense">Department of Defense</li>
<li id="energy">Department of Energy</li>
<li id="health">Department of Health and Human Services</li>
<li id="homeland">Department of Homeland Security</li>
<li id="interior">Department of the Interior</li>
<li id="transportation">Department of Transportation</li>
<li id="veterans">Department of Veteran Affairs</li>
<li id="epa">Environmental Protection Agency</li>
<li id="aeronautics">Nat'l Aeronautics and Space Admin</li>
</ul>
</ul>
<div id="agency-wrap">
<div id="agriculture">
<ul>
<li><a href="http://www.ars.usda.gov/partnering">USDA Agricultural Research Service</a></li>
<li><a href="http://www.ars.usda.gov/business/docs.htm?docid=763&page=3">USDA ARS Tech Transfer Coordinators</a></li>
<li><a href="http://www.fs.fed.us">USDA Forest Service</a></li>
</ul>
</div>
<div id="commerce">
<ul>
<li><a href="http://www.nist.gov/tpo/">DOC Nat'l Institue of Standards and Tech</a></li>
<li><a href="http://www.noaa.gov">DOC Nat'l Ocean and Atmosph Admin</a></li>
<li><a href="http://www.its.bldrdoc.gov/">DOC Institue for Telecom Sciences</a></li>
<li><a href="http://www.nist.gov/mep/">DOC Manufacturing Extension Program</a></li>
</ul>
</div>
<div id="defense">
<ul>
<li><a href="http://www.acq.osd.mil/ott/techtransit">DOD Secretary of Defense</a></li>
<li><a href="http://www.arl.army.mil/main/Main/default.cfm?Action=6">DOD Army Research Lab</a></li>
<li><a href="http://www.onr.navy.mil/en/Sciecne-Technology/Directtorates/Transition/Technology-Transfer-T2aspx">DOD Office Naval Research</a></li>
<li><a href="http://www.wpafb.af.mil/library/factsheets/factsheet.asp?id=6026">DOD Air Force Research Lab</a></li>
<li><a href="http://www.mda.mil/business/tech_apps.html">DOD Missle Defense Agency</a></li>
<li><a href="http://www.jfcom.mil/about/industry.htm">DOD Joint Forces</a></li>
<li><a href="http://www.defenseinnovationmarketplace.mil/index.html">DOD Defense Innovation Marketplace</a></li>
</ul>
</div>
<div id="energy">
<ul>
<li><a href="http://technologytransfer.energy.gov">DOE Tech Transfer Office</a></li>
</ul>
</div>
<div id="health">
<ul>
<li><a href="http://www.ott.nih.gov/">DHHS National Institutes of HealthNIH </a></li>
<li><a href="http://www.cdc.gov/od/ads/techtran/tech.htm">DHHS Centers for Disease Control</a></li>
<li><a href="http://www.fda.gov/ScienceResearch/CollaborativeOpportunities/default.htm">DHHS Food and Drug Administration</a></li>
</ul>
</div>
JS
$(function() {
$('#agency-wrap > div').addClass('agency-hide');
$('#agency ul li').click(function() {
$("#" + $(this).attr('id')).fadeIn('slow').siblings().hide();
});
});
CSS
.agency-hide {
display: none;
}
#agency {
width: 300px;
}
我还没有设计 CSS 样式,功能完成后会处理它