javascript and Internet Explorer 8
javascript and Internet Explorer 8
我有一个jsp页面,它使用JavaScript在onload页面事件中进行自动选择以及一些jQuery来动态扩展不同的div标签,其中包含一些内容。
因此,问题是,在IE8中,调用位于脚本标记中页面底部的setSelection
方法和位于名为toggle
的js方法中的jQuery方法根本不起作用。然而,在Chrome、Firefox和IE9中,它运行良好。
我在谷歌上搜索了很多这个问题,但找不到任何有用的东西。IE8中的调试器工具向我显示的唯一错误是"Object required"answers"Expression required"。
这是代码:
<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
function toggle(el)
{
var val = el.options[el.selectedIndex].value;
if (val == "1")
{
document.getElementById("2").style.display = "none";
$("#1").slideToggle(250);
}
else if (val == "2")
{
document.getElementById("1").style.display = "none";
$("#2").slideToggle(250);
}
else if (val == "0")
{
document.getElementById("1").style.display = "none";
document.getElementById("2").style.display = "none";
}
}
function setSelection(selection)
{
//Here we make dynamic selection of the combo box
var selct = document.getElementById("sel");
selct.options[selection].setAttribute("selected", "selected");
toggle(selct);
}
</script>
</head>
<body>
<select name="mySel" id = "sel" onchange="toggle(this);">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<div id="1" style="border:1px;">
</div>
<div id="2" style="border:1px;">
</div>
<script>
setSelection(0);
</script>
</body>
</html>
有人能帮我吗?
将代码包装在文档就绪函数中并尝试。
jQuery(document).ready(function($) {
// Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs;
});
相关文章:
- 视频HTML没有'无法在Internet Explorer 11上工作
- Internet Explorer缺少占位符支持,特别是密码字段
- Internet Explorer中的文本换行错误
- 为什么我在Internet Explorer上看不到html元素
- internet explorer 8兼容模式下的Youtube api错误
- 当浏览器控制台未打开时,为什么要求会导致Internet Explorer 9超时
- Internet Explorer 8. Events
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- element.dataset in Internet Explorer
- Facebook FB.init”;访问被拒绝”;在Internet Explorer 11中
- JavaScript不适用于internet explorer和Firefox,但适用于谷歌
- 在Internet Explorer中,向所选内容添加选项不起作用
- 在Internet Explorer中从二进制文件打开PDF
- elementproblem internet explorer
- 我可以使用哪些方法在Internet Explorer中禁用Alt+*X*
- 如何在Internet Explorer中使用javascript设置cookie
- 只有当alert()在带有AJAX的internet explorer中使用时,Javascript才会更新UI
- sharepoint站点的internet explorer中出现Javascript错误
- Internet Explorer重新加载IFrame
- Internet Explorer Internet Failure HTTP Status Codes