我有一个函数名称onresizeWindow()
和onresizeWindow2()
,我放在我的页面头部来改变div的高度。加载页面后更改window.onresize失败
function onResizeWindow() {
if (window.innerHeight && document.getElementById("divListItem"))
document.getElementById("divListItem").style.height = window.innerHeight - 135;
else if (document.getElementById("divListItem"))
document.getElementById("divListItem").style.height = document.body.clientHeight - 135;
}
function onResizeWindow2() {
if (window.innerHeight && document.getElementById("divListItem"))
document.getElementById("divListItem").style.height = window.innerHeight - 275;
else if (document.getElementById("divListItem"))
document.getElementById("divListItem").style.height = document.body.clientHeight - 275;
}
}
然后在我的页面的页脚我把这个
window.onresize = onResizeWindow;
onResizeWindow();
当用户点击一个按钮,我把这个代码
function showDiv(){
var tr = document.getElementById('tdSearch');
if (tr.style.display =="table-row"){
tr.style.display = "none";
window.onresize= null;
window.onresize= onResizeWindow();
onResizeWindow();
}else{
tr.style.display = "table-row";
window.onresize= null;
window.onresize= onResizeWindow2();
onResizeWindow2();
}
}
的问题是点击按钮后,页面onresize功能的页面不再工作。如何解决它?
你为什么决定在作业中加入'()',但你一开始没有?使用'window.onresize = onResizeWindow2;',例如 – Ian
感谢您的答案......但我只是意识到..im非常愚蠢......它不应该像那样... window.onresize = onResizeWindow();应该是window.onresize = onResizeWindow;和window.onresize = onResizeWindow2();应该是window.onresize = onResizeWindow2; –
我删除了方括号和那个作品 –