[英]javascript and Internet Explorer 8
I have a jsp page which is using JavaScript for automatic selection in onload page event and some jQuery to dynamically expand different div tags with some content inside. 我有一个jsp页面,它使用JavaScript在onload页面事件中进行自动选择,还有一些jQuery,用于动态扩展具有内部某些内容的div标签。
So the problem is that the calling of the setSelection
method, which is in the bottom of the page in script tags, and the jQuery methods which are in a js method called toggle
doesn't work at all in IE8. 因此问题在于,在脚本标签页面底部的
setSelection
方法的调用以及在名为toggle
的js方法中的jQuery方法在IE8中根本不起作用。 However in Chrome, Firefox and IE9 it works fine. 但是,在Chrome,Firefox和IE9中,它可以正常工作。
I've Googled this issue a lot but I can't find anything useful. 我已经用Google搜索了很多这个问题,但是找不到任何有用的东西。 The only errors which the debuger tool in IE8 show me are "Object required" and "Expression required".
IE8中的调试器工具向我显示的唯一错误是“需要对象”和“需要表达”。
Here is the code: 这是代码:
<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>
Can somebody help me? 有人可以帮我吗?
Wrap your code in document ready function and try. 将您的代码包装在文档就绪功能中,然后尝试。
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.