以下 Javascript 在 IE8 中无法运行,但在 FF、Safari、IE9 和 Chrome 中运行良好。我承认自己是 Javascript 的菜鸟,我花了 2 天时间寻找没有运气的解决方案。IE8 不喜欢切换功能或隐藏。
<!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>Untitled Document</title>
<style type="text/css">
.hide {
display: none;
}
</style>
<script type="text/javascript">
function toggleField(evt) {
evt = (evt) ? evt : event;
var target = (evt.target) ? evt.target : evt.srcElement;
var block = document.getElementById("specialty");
if (target.id == "fieldFlag1") {
block.style.display = "block";
} else {
block.style.display = "none";
}
}
</script>
</head>
<body>
<div id="profession">
Field of professional work (as applicable):
<select size="1" name="profession">
<option>-- Choose One --</option>
<option value="Architecture">Architecture</option>
<option value="FineArts">Arts, Fine</option>
<option value="PerformingArts">Arts, Performing</option>
<option value="Business">Business</option>
<option value="Consulting">Consulting</option>
<option value="Counseling">Counseling</option>
<option value="Dentistry">Dentistry</option>
<option value="Education">Education</option>
<option value="Engineering">Engineering</option>
<option value="Environment">Environment</option>
<option value="Finance">Finance</option>
<option value="Government">Government</option>
<option value="Healthcare—NonMedical">Healthcare—Non Medical</option>
<option value="HigherEducation">Higher Education</option>
<option value="InformationTechnology">Information Technology</option>
<option value="Law">Law</option>
<option value="Marketing">Marketing</option>
<option value="Media/Communications">Media/Communications</option>
<option value="Medicine">Medicine</option>
<option value="Military">Military</option>
<option value="Music">Music</option>
<option value="NonProfit">Non Profit</option>
<option value="Nursing" id="fieldFlag1" onclick="toggleField(event)">Nursing</option>
<option value="PublicService">Public Service</option>
<option value="Science/Research">Science/Research</option>
<option value="SocialServices">Social Services</option>
<option value="Sports">Sports</option>
<option value="Trade/Craft">Trade/Craft</option>
</select>
</div>
<div id="specialty" class="hide">
Choose Specialty:
<select name="Specialty" size="1">
<option value="nursing">Nursing</option>
<option value="nurse Practitioner Unspecified">Nurse·Practitioner·Unspecified</option>
<option value="nurse inactive">Nurse·Inactive</option>
<option value="womens health">Womens·Health</option>
<option value="administration">Administration</option>
<option value="hospital">Hospital</option>
<option value="critical care">Critical·Care</option>
<option value="home health">Home·Health</option>
<option value="surgical">Surgical</option>
<option value="clinical Research">Clinical·Research</option>
<option value="family health">Family·Health</option>
<option value="acute care nursing">Acute·Care·Nursing</option>
<option value="community Health Nursing">Community·Health·Nursing</option>
<option value="emergency nursing">Emergency·Nursing</option>
<option value="nurse practitioner: adult health">Nurse·Practitioner:·Adult·Health</option>
<option value="nurse practitioner: pediatrics">Nurse·Practitioner:·Pediatrics</option>
<option value="nurse practitioner: neonatal">Nurse·Practitioner:·Neonatal</option>
<option value="nurse practitioner: acute care">Nurse·Practitioner:·Acute·Care</option>
<option value="nurse practitioner: family">Nurse·Practitioner:·Family</option>
<option value="nurse practitioner: gerontology">Nurse·Practitioner:·Gerontology</option>
<option value="nurse practitioner: women's health">Nurse·Practitioner:·Women's·Health</option>
</select>
</div>
</body>
</html>