Javascript使用IF/ELSE编写变量,并将其插入其他变量中

Javascript write variable with IF/ELSE and insert it in a other var

本文关键字:变量 插入 其他 Javascript IF ELSE 使用      更新时间:2023-09-26

我有以下问题:

var widowwidth = 0,w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')      [0],x=w.innerWidth||e.clientWidth||g.clientWidth;
if( x > 1624) {
        widowwidth = 1800 / (10 + 2);
}
else {
        widowwidth = 800 / (10 + 2);
}

现在我想给meterNum变量:windowwidth

_drawSpectrum: function(analyser) {
        var that = this,
            canvas = document.getElementById('canvas'),
            cwidth = canvas.width,
            cheight = canvas.height - 2,
            meterWidth = 10, 
            gap = 10, 
            capHeight = 2,
            capStyle = '#fff',
            meterNum = windowwidth, // <----- HERE

有没有一个简单的方法,或者我犯了一些错误,因为它不起作用:(

谢谢您,Tim4497

在变量初始化和if-else语句中,您定义的是变量widowwidth而不是windowwidth。如果变量的另一半还没有死,则需要对此进行更正以使其工作。