我有简单的网页有HTML,CSS和jQuery。此页面的目的是演示水平折叠窗格。为什么对象在jQuery中的预期错误?
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.js"></script>
<title>Sample HTML</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
}
#map {
width: 10%;
height: 100%;
float: left;
}
#sidebar {
width: 89%;
height: 100%;
float: left;
border: 1px solid;
}
#toggle {
height: 10%;
float: right;
}
</style>
<script type="text/javascript">
$(window).load(function() {//this is error line
$(document).ready(function() {
$("#toggle").click(function() {
if ($(this).data('name') == 'show') {
$("#sidebar").animate({
width: '10%'
}).hide()
$("#map").animate({
width: '89%'
});
$(this).data('name', 'hide')
} else {
$("#sidebar").animate({
width: '89%'
}).show()
$("#map").animate({
width: '10%'
});
$(this).data('name', 'show')
}
});
});
});
</script>
</head>
<body>
<div id="map">
<input type="button" data-name="show" value="Toggle" id="toggle"></div>
<div id="sidebar">SIDEBAR</div>
</body>
</html>
我用IE浏览器的调试器,它在$(window).load(function()
击中说预期的对象。我不明白为什么它不起作用。
此页面也需要很长时间才能加载。
你使用像'文件的文件协议加载HTML文件://路径到file' – 2014-09-25 05:22:34
@ArunPJohny号我这是救了我的桌面上。我打开它使用IE和Chrome,都不工作。 – 2014-09-25 05:25:41
*“它保存在我的桌面上”*所以你*从文件系统加载而不是从网络服务器加载?仅供参考,您只需要'(window).load(...)'或'$(document).ready(...)',但不能同时嵌套。 – 2014-09-25 05:26:21