Javascript工作在FF + IE9,但不是IE8
Javascript Working in FF + IE9 but not IE8
正如标题所说,我的代码可以在最新的Firefox和IE9中运行,但不能在IE8中运行。有人能告诉我为什么吗?或者给我另一个基于选定元素隐藏/显示div的解决方案。由于
<script type="text/javascript">
<!--
/* Hide drop down if certain option selected */
function hideField(field_id){
var field = document.getElementById(field_id);
field.style.display = "none";
}
/* Show drop down if certain option selected */
function showField(field_id){
var field = document.getElementById(field_id);
if(field.style.display = "none"){
field.style.display = "block";
}
}
-->
</script>
<select name="subject" id="subject" >
<option value="unselected">Please Select...</option>
<option value="Advertising" onclick="hideField('browserRow'),hideField('versionRow')">Advertising</option>
<option value="Complaint" onclick="hideField('browserRow'),hideField('versionRow')">Complaint</option>
<option value="Content Issue" onclick="hideField('browserRow'),hideField('versionRow')">Content/Information</option>
<option value="Website Error" onclick="showField('browserRow'),showField('versionRow')">Website Bug/Error</option>
<option value="Website Feedback" onclick="hideField('browserRow'),hideField('versionRow')">Website Feedback</option>
<option value="Other" onclick="hideField('browserRow'),hideField('versionRow')">Other</option>
</select>
<div class="row" id="browserRow">
<label>Your Browser: <font color="#FF0000">*</font></label>
<select name="browser" id="browser">
<option value="unselected">Please Select...</option>
<option value="Android">Android</option>
<option value="Google Chrome">Google Chrome</option>
<option value="Mozilla Firefox">Mozilla Firefox</option>
<option value="Internet Explorer">Internet Explorer</option>
<option value="Safari">Safari</option>
<option value="Opera">Opera</option>
<option value="Other">Other</option>
</select>
</div>
<div class="row" id="versionRow">
<label>Browser Version: <font color="#FF0000">*</font></label>
<input type="text" name="version" value="<?php echo $session->userinfo['version']; ?>" maxlength="10" id="bVersion">
<span class="error"><?php echo $form->error("version"); ?></span>
<script language="javascript">
var number = document.getElementById('version');
selectItemByValue(number, '<?php echo $form->value('version'); ?>');
</script>
</div>
IE不支持<option>
的onclick
。
解决方法是在<select>
上使用onchange
。
详细说明请参见IE capture option element onclick
试着在这里用分号代替逗号:
onclick="hideField('browserRow');hideField('versionRow')"
这里的一个大问题是在您的showField
函数:
if(field.style.display = "none")
这行代码不正确。您在if()
中使用了单个相等而不是双相等,因此它将设置显示属性的值,而不是检查值是什么。
这不是导致IE8问题的原因,但这是一个需要指出的严重错误。(虽然纯粹是运气,在这种情况下可能不会给您造成任何问题)
相关文章:
- 为什么jQuery 1.8不能在IE8和InternetExplorer9中使用?(截至2012年9月的IE9最新版本)
- javascript/jQuery:在title中添加换行符——在IE9中有效,但在IE8中无效
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- XDomainRequest (CORS) for XML 导致 IE8 / IE9 中的“访问被拒绝”错误
- IE8或IE9-支持多文件选择上传,无需Flash和HTML5
- IE8/IE9检测是否启用了第三方cookie,如果没有,则启用
- IE8不允许javascript引用,但IE9允许
- IE9中的有效输出,但IE7/IE8中的未定义输出
- IE8 与 IE9 兼容性
- Request.UrlReferrer在IE8中无法正常工作,并且工作正常IE9
- 谷歌图表适用于IE7,但不适用于IE8或IE9
- OnBeforeUnload ajax 请求在 IE8 和 IE9 上不起作用
- 带有 Wordpress 主题的 ie8 和 ie9 中的 Jquery 错误.(对象不支持此属性或方法)
- iframe 内容在 IE8 - IE9 中完全加载
- ExtJs-IE8+IE9上的文件上载错误
- IE8/IE9中的跨原点标头
- 在ie8, IE9中发送图像数据到服务器
- 带有localhost或LAN服务器名称的IE8/IE9上的localStorage;不起作用
- 不能执行自由脚本中的代码- IE6 IE7 IE8 IE9
- 如何使用CSS3转换整个页面,并支持IE8, IE9