[英]javascript and Internet Explorer 8
我有一个jsp页面,它使用JavaScript在onload页面事件中进行自动选择,还有一些jQuery,用于动态扩展具有内部某些内容的div标签。
因此问题在于,在脚本标签页面底部的setSelection
方法的调用以及在名为toggle
的js方法中的jQuery方法在IE8中根本不起作用。 但是,在Chrome,Firefox和IE9中,它可以正常工作。
我已经用Google搜索了很多这个问题,但是找不到任何有用的东西。 IE8中的调试器工具向我显示的唯一错误是“需要对象”和“需要表达”。
这是代码:
<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;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.