这行不通,我不知道哪里出错了:
<style>
* {
margin: 0px
}
div {
height: 250px;
width: 630px;
overflow: hidden;
vertical-align: top;
position: relative;
}
iframe {
position: absolute;
left: -50px;
top: -130px;
}
</style>
<script>
window.onload = function() {
document.getElementsByTagName('body')[0].onkeyup = function(e) {
var div = document.getElementById('capture');
if(e.keyCode == 70) {
if(div.style.height == 250){
alert("Yes");
}
else {alert("no");}
}
}
};
</script>
++++++++++++++编辑++++++++++++++
好的,这很好用:
if(div.style.height < '260px'){
alert("Yes!");
div.style.height = '475px';
pan.style.top = '-25';
}
else if(div.style.height > '260px') {
alert("no");
div.style.height = '250px';
pan.style.top = '-130';
}
但这不是:
if(div.style.height = '250px'){
alert("Yes!");
div.style.height = '475px';
pan.style.top = '-25';
}
else if(div.style.height = '475px') {
alert("no");
div.style.height = '250px';
pan.style.top = '-130';
}
什么给了?!?
最佳答案
div.style.height
返回 "250px"
字符串而不是 250
数字,所以你的 if(div.style. height == 250){
不满足条件。
关于Javascript 高度声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4532878/