当窗口调整大小时,我希望更改表的宽度,因为我需要将全局变量作为参数传递给函数,但是当我传递变量它不能工作并且不能在方法中使用变量时,我如何修复它,谢谢您的帮助。
var WOS = document.body.parentNode.clientWidth;
var HOS = document.body.parentNode.clientHeight;
$(window).resize(function(){
tableSetup(WOS, HOS);
}
function tableSetup(WOS, HOS) {
alert(WOS); // give undefined message
}
发布于 2015-07-24 20:59:42
由于您希望获得有关调整大小的更新值,因此需要在“调整大小”事件中计算teh值。
var WOS = document.body.parentNode.clientWidth;
var HOS = document.body.parentNode.clientHeight;
$(window).resize(function() {
WOS = document.body.parentNode.clientWidth;
HOS = document.body.parentNode.clientHeight;
tableSetup(WOS, HOS);
})
function tableSetup(WOS, HOS) {
snippet.log(WOS); // give undefined message
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
演示:小提琴
https://stackoverflow.com/questions/31622842
复制相似问题