gpt4 book ai didi

Javascript 不能在 IE8 中运行

转载 作者:行者123 更新时间:2023-11-30 06:36:09 25 4
gpt4 key购买 nike

以下 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&#8212;Non&#160;Medical</option>
<option value="HigherEducation">Higher&#160;Education</option>
<option value="InformationTechnology">Information&#160;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&#160;Profit</option>
<option value="Nursing" id="fieldFlag1" onclick="toggleField(event)">Nursing</option>
<option value="PublicService">Public&#160;Service</option>
<option value="Science/Research">Science/Research</option>
<option value="SocialServices">Social&#160;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>

最佳答案

在您第一次选择更改时

var e = document.getElementById("your First Select");
var valueOption= e.options[e.selectedIndex].value;
var block = document.getElementById("specialty");

if (valueOption == "Nursing")
block.style.display = "block";
} else {
block.style.display = "none";
}

关于Javascript 不能在 IE8 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14344108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com