如果说有一个时期让人讨厌 IE,那就是现在了。此代码以一个包含内容的框开始。单击按钮时,该框应该下拉并淡入。
<html>
<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript'>
function Test()
{
var item_height = $('#test').height();
$('#test').height(0);
$('#test').css('opacity','0');
$('#test').animate({ height: item_height, opacity: '1' },400);
}
</script>
<body>
<!-- The div below holds the sample content -->
<div id="test" style='border: 1px solid black;'>
Content<br>
Content<br>
Content<br>
Content<br>
Content
</div>
<!-- The button to test the animation -->
<br><br>
<div style='position: absolute; top: 150px; left: 10px;'>
<button onclick='Test();'>Test</button>
</div>
</body>
</html>
这个非常简单的示例适用于 Chrome、Safari 和 Opera。但是 Internet Explorer 呢? 不。
我怎样才能(如果可能的话)修复这个问题,以便它在 IE 中正常工作?
最佳答案
因为您缺少 <head>
标签和文档类型声明,您的页面正在以 Quirks 模式呈现。改变这个
<html>
到此
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
关于jquery - 如何使这个 jQuery 代码片段在 Internet Explorer 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2686836/